Sha256: 48a17a79804f1587f1501189df784b0e0ffe9c26b74773d5deb5295effeb9595

Contents?: true

Size: 1.77 KB

Versions: 16

Compression:

Stored size: 1.77 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.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.rb"
    Then the stdout should match "2 examples, 1 failure"
    Then the stdout should match "should have been changed by 2, but was changed by 1"

  Scenario: expecting no change
    Given a file named "expect_no_change.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.rb"
    Then the stdout should match "2 examples, 1 failure"
    Then the stdout should match "should not have changed, but did change from 1 to 2"

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
rspec-core-2.0.0.beta.2 features-pending/expectations/expect_change.feature
rspec-core-2.0.0.beta.1 features-pending/expectations/expect_change.feature
rspec-core-2.0.0.a10 features-pending/expectations/expect_change.feature
rspec-core-2.0.0.a9 features-pending/expectations/expect_change.feature
rspec-core-2.0.0.a8 features-pending/expectations/expect_change.feature
rspec-core-2.0.0.a7 features-pending/expectations/expect_change.feature
rspec-core-2.0.0.a6 features-pending/expectations/expect_change.feature
rspec-core-2.0.0.a5 features-pending/expectations/expect_change.feature
rspec-core-2.0.0.a4 features-pending/expectations/expect_change.feature
rspec-core-2.0.0.a3 features-pending/expectations/expect_change.feature
rspec-core-2.0.0.a2 features-pending/expectations/expect_change.feature
rspec-core-2.0.0.a1 features-pending/expectations/expect_change.feature
rspec-1.2.7 features/expectations/expect_change.feature
rspec-1.2.8 features/expectations/expect_change.feature
rspec-1.2.5 features/expectations/expect_change.feature
rspec-1.2.6 features/expectations/expect_change.feature