Sha256: 2703af32ec2865397eb224fce1fd42128ec690ed06c81b5e8ebe73c9691b65ef

Contents?: true

Size: 1.7 KB

Versions: 17

Compression:

Stored size: 1.7 KB

Contents

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

Version data entries

17 entries across 17 versions & 5 rubygems

Version Path
rspec-activemodel-mocks-1.2.1 features/mocks/stub_model.feature
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rspec-activemodel-mocks-1.2.0/features/mocks/stub_model.feature
rspec-activemodel-mocks-1.2.0 features/mocks/stub_model.feature
rspec-activemodel-mocks-1.1.0 features/mocks/stub_model.feature
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/rspec-activemodel-mocks-1.0.3/features/mocks/stub_model.feature
rspec-activemodel-mocks-1.0.3 features/mocks/stub_model.feature
rspec-activemodel-mocks-1.0.2 features/mocks/stub_model.feature
solidus_backend-1.0.0.pre3 vendor/bundle/gems/rspec-activemodel-mocks-1.0.1/features/mocks/stub_model.feature
solidus_backend-1.0.0.pre2 vendor/bundle/gems/rspec-activemodel-mocks-1.0.1/features/mocks/stub_model.feature
solidus_backend-1.0.0.pre vendor/bundle/gems/rspec-activemodel-mocks-1.0.1/features/mocks/stub_model.feature
rspec-activemodel-mocks-1.0.1 features/mocks/stub_model.feature
rspec-activemodel-mocks-1.0.0 features/mocks/stub_model.feature
rspec-activemodel-mocks-1.0.0.beta1 features/mocks/stub_model.feature
rspec-rails-3.0.0.beta2 features/mocks/stub_model.feature
rspec-rails-2.99.0.beta2 features/mocks/stub_model.feature
rspec-rails-3.0.0.beta1 features/mocks/stub_model.feature
rspec-rails-2.99.0.beta1 features/mocks/stub_model.feature