Sha256: 811e8e89bf67bfb39911ec50c930dd48cb53f4c6355e2806c1f13db63b5408ec

Contents?: true

Size: 1.66 KB

Versions: 36

Compression:

Stored size: 1.66 KB

Contents

Feature: expect change

  Expect the execution of a block of code to change the state of an object.

  Background:
    Given a file named "lib/counter.rb" with:
      """ruby
      class Counter
        class << self
          def increment
            @count ||= 0
            @count += 1
          end

          def count
            @count ||= 0
          end
        end
      end
      """

  Scenario: expect change
    Given a file named "spec/example_spec.rb" with:
      """ruby
      require "counter"

      describe Counter, "#increment" do
        it "should increment the count" do
          expect { Counter.increment }.to change{Counter.count}.from(0).to(1)
        end

        # deliberate failure
        it "should increment the count by 2" do
          expect { Counter.increment }.to change{Counter.count}.by(2)
        end
      end
      """
    When I run `rspec spec/example_spec.rb`
    Then the output should contain "1 failure"
    Then the output should contain "should have been changed by 2, but was changed by 1"

  Scenario: expect no change
    Given a file named "spec/example_spec.rb" with:
      """ruby
      require "counter"

      describe Counter, "#increment" do
        it "should not increment the count by 1 (using not_to)" do
          expect { Counter.increment }.not_to change{Counter.count}
        end

        it "should not increment the count by 1 (using to_not)" do
          expect { Counter.increment }.to_not change{Counter.count}
        end
      end
      """
    When I run `rspec spec/example_spec.rb`
    Then the output should contain "2 failures"
    Then the output should contain "should not have changed, but did change from 1 to 2"

Version data entries

36 entries across 36 versions & 8 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rspec-expectations-2.14.5/features/built_in_matchers/expect_change.feature
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-expectations-2.14.5/features/built_in_matchers/expect_change.feature
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-expectations-2.14.5/features/built_in_matchers/expect_change.feature
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/features/built_in_matchers/expect_change.feature
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/features/built_in_matchers/expect_change.feature
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/features/built_in_matchers/expect_change.feature
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/features/built_in_matchers/expect_change.feature
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-expectations-2.14.5/features/built_in_matchers/expect_change.feature
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-expectations-2.14.5/features/built_in_matchers/expect_change.feature
rspec-expectations-2.99.2 features/built_in_matchers/expect_change.feature
dxruby_rp5-0.0.4 spec/vendor/rspec-expectations-2.14.4/features/built_in_matchers/expect_change.feature
rspec-expectations-2.99.1 features/built_in_matchers/expect_change.feature
rspec-expectations-2.99.0 features/built_in_matchers/expect_change.feature
rspec-expectations-2.99.0.rc1 features/built_in_matchers/expect_change.feature
rspec-expectations-2.99.0.beta2 features/built_in_matchers/expect_change.feature
rspec-expectations-2.14.5 features/built_in_matchers/expect_change.feature
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rspec-expectations-2.14.4/features/built_in_matchers/expect_change.feature
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/rspec-expectations-2.14.4/features/built_in_matchers/expect_change.feature
dxruby_rp5-0.0.3 spec/vendor/rspec-expectations-2.14.4/features/built_in_matchers/expect_change.feature
tuktuk-rails-0.0.10 vendor/bundle/ruby/2.0.0/gems/rspec-expectations-2.14.4/features/built_in_matchers/expect_change.feature