spec/rspec/rails/mocks/mock_model_spec.rb in rspec-rails-2.0.0.beta.17 vs spec/rspec/rails/mocks/mock_model_spec.rb in rspec-rails-2.0.0.beta.18

- old
+ new

@@ -1,9 +1,44 @@ require 'spec_helper' require File.dirname(__FILE__) + '/ar_classes' describe "mock_model(RealModel)" do + + context "given a String" do + context "that does not represent an existing constant" do + it "class says it's name" do + model = mock_model("Foo") + model.class.name.should eq("Foo") + end + end + + context "that represents an existing constant" do + context "that extends ActiveModel::Naming" do + it "treats the constant as the class" do + model = mock_model("MockableModel") + model.class.name.should eq("MockableModel") + end + end + + context "that does not extend ActiveModel::Naming" do + it "raises with a helpful message" do + expect do + mock_model("String") + end.to raise_error(ArgumentError) + end + end + end + end + + context "given a class that does not extend ActiveModel::Naming" do + it "raises with a helpful message" do + expect do + mock_model(String) + end.to raise_error(ArgumentError) + end + end + describe "with #id stubbed" do before(:each) do @model = mock_model(MockableModel, :id => 1) end it "is named using the stubbed id value" do @@ -103,21 +138,10 @@ it "does not say it instance_of? if RealModel isn't, even if it's ancestor is" do @model.instance_of?(MockableModel).should be(false) end end - describe "#model_name" do - before(:each) do - @model = mock_model(SubMockableModel) - end - - it "says its model_name" do - @model.model_name.should == "SubMockableModel" - end - end - - describe "#destroyed?" do context "default" do it "returns false" do @model = mock_model(SubMockableModel) @model.destroyed?.should be(false) @@ -197,8 +221,7 @@ end def model mock_model(MockableModel, :id => nil) end - end end