Permalink
Browse files

Remove mock_model and stub_model from rspec-rails

Some tests still fail without them as I have not yet figured out
a good way to fix them yet. View scaffold generators are also
currently broken.

rspec/rspec-rails#894
  • Loading branch information...
1 parent bf8b1e9 commit 29c175832f55d180473f35c22d1b88245a828917 @thomas-holmes thomas-holmes committed with alindeman Dec 29, 2013
@@ -1,147 +0,0 @@
-Feature: mock_model
-
- The `mock_model` method generates a test double that acts like an instance of
- `ActiveModel`. This is different from the `stub_model` method which generates
- an instance of a real model class.
-
- The benefit of `mock_model` over `stub_model` is that it is a true double, so
- the examples are not dependent on the behavior (or mis-behavior), or even the
- existence of any other code. If you're working on a controller spec and you
- need a model that doesn't exist, you can pass `mock_model` a string and the
- generated object will act as though its an instance of the class named by
- that string.
-
- Scenario: passing a string that represents a non-existent constant
- Given a file named "spec/models/car_spec.rb" with:
- """ruby
- require "spec_helper"
-
- describe "mock_model('Car') with no Car constant in existence" do
- it "generates a constant" do
- expect(Object.const_defined?(:Car)).to be_falsey
- mock_model("Car")
- expect(Object.const_defined?(:Car)).to be_truthy
- end
-
- describe "generates an object that ..." do
- it "returns the correct name" do
- car = mock_model("Car")
- expect(car.class.name).to eq("Car")
- end
-
- it "says it is a Car" do
- car = mock_model("Car")
- expect(car).to be_a(Car)
- end
- end
- end
- """
- When I run `rspec spec/models/car_spec.rb`
- Then the examples should all pass
-
- Scenario: passing a string that represents an existing constant
- Given a file named "spec/models/widget_spec.rb" with:
- """ruby
- require "spec_helper"
-
- describe Widget do
- it "uses the existing constant" do
- widget = mock_model("Widget")
- expect(widget).to be_a(Widget)
- end
- end
- """
- When I run `rspec spec/models/widget_spec.rb`
- Then the examples should all pass
-
- Scenario: passing a class that does not extend ActiveModel::Naming
- Given a file named "spec/models/string_spec.rb" with:
- """ruby
- require "spec_helper"
-
- describe String do
- it "raises" do
- expect { mock_model(String) }.to raise_exception
- end
- end
- """
- When I run `rspec spec/models/string_spec.rb`
- Then the examples should all pass
-
- Scenario: passing an Active Record constant
- Given a file named "spec/models/widget_spec.rb" with:
- """ruby
- require "spec_helper"
-
- describe Widget do
- let(:widget) { mock_model(Widget) }
-
- it "is valid by default" do
- expect(widget).to be_valid
- end
-
- it "is not a new record by default" do
- expect(widget).not_to be_new_record
- end
-
- it "can be converted to a new record" do
- expect(widget.as_new_record).to be_new_record
- end
-
- it "sets :id to nil upon destroy" do
- widget.destroy
- expect(widget.id).to be_nil
- end
- end
- """
- When I run `rspec spec/models/widget_spec.rb`
- Then the examples should all pass
-
- Scenario: passing an Active Record constant with method stubs
- Given a file named "spec/models/widget_spec.rb" with:
- """ruby
- require "spec_helper"
-
- describe "mock_model(Widget) with stubs" do
- let(:widget) do
- mock_model Widget, :foo => "bar",
- :save => true,
- :update_attributes => false
- end
-
- it "supports stubs for methods that don't exist in ActiveModel or ActiveRecord" do
- expect(widget.foo).to eq("bar")
- end
-
- it "supports stubs for methods that do exist" do
- expect(widget.save).to eq(true)
- expect(widget.update_attributes).to be_falsey
- end
-
- describe "#errors" do
- context "with update_attributes => false" do
- it "is not empty" do
- expect(widget.errors).not_to be_empty
- end
- end
- end
- end
- """
- When I run `rspec spec/models/widget_spec.rb`
- Then the examples should all pass
-
- Scenario: mock_model outside rails
- Given a file named "mock_model_outside_rails_spec.rb" with:
- """ruby
- require 'rspec/rails/mocks'
-
- describe "Foo" do
- it "is mockable" do
- foo = mock_model("Foo")
- expect(foo.id).to eq(1001)
- expect(foo.to_param).to eq("1001")
- end
- end
- """
- When I run `rspec mock_model_outside_rails_spec.rb`
- Then the examples should all pass
@@ -1,58 +0,0 @@
-Feature: stub_model
-
- The stub_model method generates an instance of a Active Model model.
-
- While you can use stub_model in any example (model, view, controller,
- helper), it is especially useful in view examples, which are inherently
- more state-based than interaction-based.
-
- Scenario: passing an Active Record constant with a hash of stubs
- Given a file named "spec/models/widget_spec.rb" with:
- """ruby
- require "spec_helper"
-
- describe "stub_model(Widget) with a hash of stubs" do
- let(:widget) do
- stub_model Widget, :id => 5, :random_attribute => true
- end
-
- it "stubs :id" do
- expect(widget.id).to eql(5)
- end
-
- it "stubs :random_attribute" do
- expect(widget.random_attribute).to be_truthy
- end
-
- it "returns false for new_record? if :id is set" do
- expect(widget).not_to be_new_record
- end
-
- it "can be converted to a new record" do
- widget.as_new_record
- expect(widget).to be_new_record
- end
- end
- """
- When I run `rspec spec/models/widget_spec.rb`
- Then the examples should all pass
-
- Scenario: passing an Active Record constant with a block of stubs
- Given a file named "spec/models/widget_spec.rb" with:
- """ruby
- require "spec_helper"
-
- describe "stub_model(Widget) with a block of stubs" do
- let(:widget) do
- stub_model Widget do |widget|
- widget.id = 5
- end
- end
-
- it "stubs :id" do
- expect(widget.id).to eql(5)
- end
- end
- """
- When I run `rspec spec/models/widget_spec.rb`
- Then the examples should all pass
View
@@ -12,6 +12,5 @@
require 'rspec/rails/adapters'
require 'rspec/rails/matchers'
require 'rspec/rails/fixture_support'
-require 'rspec/rails/mocks'
require 'rspec/rails/example'
require 'rspec/rails/vendor/capybara'
Oops, something went wrong.

0 comments on commit 29c1758

Please sign in to comment.