Sha256: 3d80acb0d0b8cee25ae37406d5bc6b39cb459ca34bd8aff770833037ce2b085a

Contents?: true

Size: 1.75 KB

Versions: 5

Compression:

Stored size: 1.75 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 "spec expect_change_spec.rb"
    Then I should see "2 examples, 1 failure"
    Then I should see "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 "spec expect_no_change_spec.rb"
    Then I should see "2 examples, 1 failure"
    Then I should see "should not have changed, but did change from 1 to 2"

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rspec-expectations-2.0.0.beta.7 features/matchers/expect_change.feature
rspec-expectations-2.0.0.beta.6 features/matchers/expect_change.feature
rspec-expectations-2.0.0.beta.5 features/matchers/expect_change.feature
rspec-expectations-2.0.0.beta.4 features/matchers/expect_change.feature
rspec-expectations-2.0.0.beta.3 features/matchers/expect_change.feature