Skip to content

Instantly share code, notes, and snippets.

@erubboli
Created August 10, 2012 17:48
Show Gist options
  • Select an option

  • Save erubboli/3316106 to your computer and use it in GitHub Desktop.

Select an option

Save erubboli/3316106 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe Nasreddin::Resource do
let(:foo) { double(:foo) }
before do
TorqueBox::Messaging::Queue.stub(:new).and_return(double().as_null_object)
end
def stub_remote_call_and_ensure(&block)
Foo.should_receive(:remote_call).with do |*args|
a=args.pop
a.should be_an_instance_of(Hash)
block.call(a)
end.and_return(foo)
end
describe "as consumer" do
it "should be able to search an object by :id" do
stub_remote_call_and_ensure do |arg|
arg[:method].should == 'GET'
arg[:id].should == 1
end
Foo.find(1).should eq(foo)
end
it "should be able to search an object by params" do
stub_remote_call_and_ensure do |arg|
arg[:method].should == 'GET'
arg[:params].should == { foo: 'bar' }
arg[:id].should be_nil
end
Foo.find(foo: 'bar').should eq(foo)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment