Sha256: d2910cf2b302950826ac2bccabe7b2011b4c78e7c39141b3379cd3df5bd4f2ce

Contents?: true

Size: 1.81 KB

Versions: 7

Compression:

Stored size: 1.81 KB

Contents

Feature: expect change

  Expect some code (wrapped in a proc) to change the state of some object.
  
  Scenario: expecting change
    Given a file named "expect_change_spec.rb" with:
      """
      class Counter
        class << self
          def increment
            @count ||= 0
            @count += 1
          end
          
          def count
            @count ||= 0
          end
        end
      end
      
      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 ./expect_change_spec.rb"
    Then the output should contain "2 examples, 1 failure"
    Then the output should contain "should have been changed by 2, but was changed by 1"

  Scenario: expecting no change
    Given a file named "expect_no_change_spec.rb" with:
      """
      class Counter
        class << self
          def increment
            @count ||= 0
            @count += 1
          end
          
          def count
            @count ||= 0
          end
        end
      end

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

        # deliberate failure
        it "should not increment the count by 1" do
          expect{Counter.increment}.to_not change{Counter.count}.by(1)
        end
      end
      """
    When I run "rspec ./expect_no_change_spec.rb"
    Then the output should contain "2 examples, 1 failure"
    Then the output should contain "should not have changed, but did change from 1 to 2"

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rspec-expectations-2.4.0 features/built_in_matchers/expect_change.feature
rspec-expectations-2.0.0.rc features/matchers/expect_change.feature
rspec-expectations-2.0.0.beta.22 features/matchers/expect_change.feature
rspec-expectations-2.0.0.beta.20 features/matchers/expect_change.feature
rspec-expectations-2.0.0.beta.19 features/matchers/expect_change.feature
rspec-expectations-2.0.0.beta.18 features/matchers/expect_change.feature
rspec-expectations-2.0.0.beta.17 features/matchers/expect_change.feature