spec/unit/proxyable_spec.rb in couchrest_model-2.0.4 vs spec/unit/proxyable_spec.rb in couchrest_model-2.1.0.beta1
- old
+ new
@@ -25,13 +25,13 @@
it "should respond to method" do
@obj.should respond_to(:proxy_database)
end
it "should provide proxy database from method" do
- @class.stub!(:proxy_database_method).twice.and_return(:slug)
- @obj.proxy_database.should be_a(CouchRest::Database)
- @obj.proxy_database.name.should eql('couchrest_proxy')
+ expect(@class).to receive(:proxy_database_method).at_least(:twice).and_return(:slug)
+ expect(@obj.proxy_database).to be_a(CouchRest::Database)
+ expect(@obj.proxy_database.name).to eql('couchrest_proxy')
end
it "should raise an error if called and no proxy_database_method set" do
lambda { @obj.proxy_database }.should raise_error(StandardError, /Please set/)
end
@@ -82,11 +82,11 @@
@class.proxy_for(:cats)
@class.proxy_method_names.should eql([:cats])
end
it "should create a new method" do
- DummyProxyable.stub!(:method_defined?).and_return(true)
+ DummyProxyable.stub(:method_defined?).and_return(true)
DummyProxyable.proxy_for(:cats)
DummyProxyable.new.should respond_to(:cats)
end
describe "generated method" do
@@ -176,14 +176,14 @@
before :all do
@klass = CouchRest::Model::Proxyable::ModelProxy
end
before :each do
- @design_doc = mock('Design')
- @design_doc.stub!(:view_names).and_return(['all', 'by_name'])
- @model = mock('Cat')
- @model.stub!(:design_docs).and_return([@design_doc])
+ @design_doc = double('Design')
+ @design_doc.stub(:view_names).and_return(['all', 'by_name'])
+ @model = double('Cat')
+ @model.stub(:design_docs).and_return([@design_doc])
@obj = @klass.new(@model, 'owner', 'owner_name', 'database')
end
describe "initialization" do
@@ -211,19 +211,19 @@
@model.should_receive(:by_name).with(:proxy => @obj).and_return(nil)
@obj.by_name
end
it "should create 'find_by_name' view that forwards to normal view" do
- view = mock('view')
+ view = double('view')
view.should_receive('key').with('name').and_return(view)
view.should_receive('first').and_return(nil)
@obj.should_receive(:by_name).and_return(view)
@obj.find_by_name('name')
end
it "should create 'find_by_name!' that raises error when there are no results" do
- view = mock('view')
+ view = double('view')
view.should_receive('key').with('name').and_return(view)
view.should_receive('first').and_return(nil)
@obj.should_receive(:by_name).and_return(view)
lambda { @obj.find_by_name!('name') }.should raise_error(CouchRest::Model::DocumentNotFound)
end
@@ -241,25 +241,25 @@
@obj.should_receive(:proxy_block_update).with(:build_from_database, 'attrs', 'opts')
@obj.build_from_database('attrs', 'opts')
end
it "should proxy #count" do
- view = mock('View')
+ view = double('View')
view.should_receive(:count).and_return(nil)
@model.should_receive(:all).and_return(view)
@obj.count
end
it "should proxy #first" do
- view = mock('View')
+ view = double('View')
view.should_receive(:first).and_return(nil)
@model.should_receive(:all).and_return(view)
@obj.first
end
it "should proxy #last" do
- view = mock('View')
+ view = double('View')
view.should_receive(:last).and_return(nil)
@model.should_receive(:all).and_return(view)
@obj.last
end
@@ -277,19 +277,19 @@
### Updating methods
describe "#proxy_update" do
it "should set returned doc fields" do
- doc = mock(:Document)
+ doc = double(:Document)
doc.should_receive(:is_a?).with(@model).and_return(true)
doc.should_receive(:database=).with('database')
doc.should_receive(:model_proxy=).with(@obj)
doc.should_receive(:send).with('owner_name=', 'owner')
@obj.send(:proxy_update, doc).should eql(doc)
end
it "should not set anything if matching document not provided" do
- doc = mock(:DocumentFoo)
+ doc = double(:DocumentFoo)
doc.should_receive(:is_a?).with(@model).and_return(false)
doc.should_not_receive(:database=)
doc.should_not_receive(:model_proxy=)
doc.should_not_receive(:owner_name=)
@obj.send(:proxy_update, doc).should eql(doc)