I am in the middle of refactoring out part of a ruby on rails codebase into a ruby gem. As part of the process, I have to shift some test cases over to the gem.
For one of the tests:
describe A::B do
describe "#someMethod" do
let(:user_hash) { {'id' => 3, "username" => "user", "email" => "[email protected]"} }
it "return the base64 message" do
described_class.message(user_hash).should ==
Base64.encode64(user_hash.to_json).gsub("\n", "")
end
The thing is, plain hashes do not have the to_json method, so I keep getting a NoMethodError when I run the tests. The to_json method seems to be derived from activeresource (https://github.com/rails/activeresource). How do I now augment the hash with the to_json method?
Thank you.
require 'json'at the top.