spec/unit/contextio/api/resource_spec.rb in contextio-1.5.0 vs spec/unit/contextio/api/resource_spec.rb in contextio-1.6.0

- old
+ new

@@ -120,11 +120,11 @@ it "returns the value set" do expect(subject.foo).to eq('foo') end it "doesn't try to fetch from the API" do - subject.should_not_receive(:fetch_attributes) + expect(subject).to_not receive(:fetch_attributes) subject.foo end it "subs '-' for '_' in attribute names" do @@ -132,11 +132,11 @@ end end context "when the attributes is not set at creation" do it "tries to fetch from the API" do - api.should_receive(:request).with(:get, 'resource_url'). + expect(api).to receive(:request).with(:get, 'resource_url'). and_return({'foo' => 'set from API', 'longer-name' => 'bar'}) subject.foo end @@ -162,11 +162,11 @@ context "when one isn't passed in at creation" do context "and one is returned from the API" do subject { helper_class.new(api, resource_url: 'resource_url') } before do - api.stub(:request).and_return( + allow(api).to receive(:request).and_return( { 'resource' => { 'resource_url' => 'relation_url' } } @@ -176,11 +176,11 @@ it "makes a related object available" do expect(subject.resource).to be_a(Resource) end it "passes keys from the api response to the new object" do - Resource.should_receive(:new).with(api, 'resource_url' => 'relation_url') + expect(Resource).to receive(:new).with(api, 'resource_url' => 'relation_url') subject.resource end it "returns the same object each time" do @@ -190,11 +190,11 @@ context "and one isn't returned from the API" do subject { helper_class.new(api, resource_url: 'resource_url') } before do - api.stub(:request).and_return({ }) + allow(api).to receive(:request).and_return({ }) end it "makes the resource nil" do expect(subject.resource).to be_nil end @@ -202,11 +202,11 @@ context "and the API returns an empty hash" do subject { helper_class.new(api, resource_url: 'resource_url') } before do - api.stub(:request).and_return( + allow(api).to receive(:request).and_return( { 'resource' => { } } ) end @@ -218,11 +218,11 @@ context "and the API returns an empty array" do subject { helper_class.new(api, resource_url: 'resource_url') } before do - api.stub(:request).and_return( + allow(api).to receive(:request).and_return( { 'resource' => [ ] } ) end @@ -241,11 +241,11 @@ it "makes the passed-in related object available" do expect(subject.resource).to be(relation_object) end it "doesn't make any API calls" do - api.should_not_receive(:request) + expect(api).to_not receive(:request) subject.resource end end end @@ -263,11 +263,11 @@ context "when a collection isn't passed in at creation" do context "and a collection is returned from the API" do subject { helper_class.new(api, resource_url: 'resource_url') } before do - api.stub(:request).and_return( + allow(api).to receive(:request).and_return( { 'resources' => [{ 'resource_url' => 'relation_url' }] } @@ -277,46 +277,46 @@ it "makes a related collection object available" do expect(subject.resources).to be_a(ResourceCollection) end it "passes keys from the api response to the new object" do - ResourceCollection.should_receive(:new).with(api, hash_including(attribute_hashes: [{'resource_url' => 'relation_url'}])) + expect(ResourceCollection).to receive(:new).with(api, hash_including(attribute_hashes: [{'resource_url' => 'relation_url'}])) subject.resources end it "returns the same object each time" do expect(subject.resources).to be(subject.resources) end it "passes its self to the new collection" do - ResourceCollection.should_receive(:new).with(anything, hash_including(:helper_class => subject)) + expect(ResourceCollection).to receive(:new).with(anything, hash_including(:helper_class => subject)) subject.resources end end context "and a collection isn't returned from the API" do subject { helper_class.new(api, resource_url: 'resource_url') } before do - api.stub(:request).and_return({ 'foo' => 'bar' }) + allow(api).to receive(:request).and_return({ 'foo' => 'bar' }) end it "tries the API only once" do - api.should_receive(:request).exactly(:once).and_return({ 'foo' => 'bar' }) + expect(api).to receive(:request).exactly(:once).and_return({ 'foo' => 'bar' }) subject.resources subject.resources end it "still builds a relation object" do expect(subject.resources).to be_a(ResourceCollection) end it "passes its self to the new collection" do - ResourceCollection.should_receive(:new).with(anything, hash_including(:helper_class => subject)) + expect(ResourceCollection).to receive(:new).with(anything, hash_including(:helper_class => subject)) subject.resources end end end @@ -329,11 +329,11 @@ it "makes a collection object available" do expect(subject.resources).to be_a(ResourceCollection) end it "doesn't make any API calls" do - api.should_not_receive(:request) + expect(api).to_not receive(:request) subject.resources end end end @@ -348,17 +348,17 @@ subject do helper_class.new(api, resource_url: 'resource_url') end it "makes a request to the API" do - subject.api.should_receive(:request).with(:get, 'resource_url').and_return({}) + expect(subject.api).to receive(:request).with(:get, 'resource_url').and_return({}) subject.send(:fetch_attributes) end it "defines getter methods for new attributes returned" do - subject.api.stub(:request).and_return(foo: 'bar') + allow(subject.api).to receive(:request).and_return(foo: 'bar') subject.send(:fetch_attributes) expect(subject.foo).to eq('bar') end @@ -366,19 +366,19 @@ it "doesn't override existing getter methods" do def subject.foo 'hard coded value' end - subject.api.stub(:request).and_return(foo: 'bar') + allow(subject.api).to receive(:request).and_return(foo: 'bar') subject.send(:fetch_attributes) expect(subject.foo).to eq('hard coded value') end it "stores the response hash" do - subject.api.stub(:request).and_return('foo' => 'bar') + allow(subject.api).to receive(:request).and_return('foo' => 'bar') subject.send(:fetch_attributes) expect(subject.api_attributes).to eq('foo' => 'bar') end @@ -398,11 +398,11 @@ subject do helper_class.new(api, resource_url: 'resource_url') end it "hits the API only on first call" do - api.should_receive(:request).exactly(:once) + expect(api).to receive(:request).exactly(:once) subject.api_attributes subject.api_attributes end @@ -434,11 +434,11 @@ subject do helper_class.new(api, id: '33f1') end it "delegates URL construction to the api" do - api.should_receive(:url_for).with(subject).and_return('helpers/33f1') + expect(api).to receive(:url_for).with(subject).and_return('helpers/33f1') expect(subject.resource_url).to eq('helpers/33f1') end end end @@ -453,10 +453,10 @@ subject do helper_class.new(double('api', :request => {'success' => true}), resource_url: 'resource_url') end it "makes a request to the API" do - subject.api.should_receive(:request).with(:delete, 'resource_url') + expect(subject.api).to receive(:request).with(:delete, 'resource_url') subject.delete end it "returns the contents of the 'success' key" do