Sha256: 6c7af46f419210b47be59eacf3136676217c9afc8e248d29391644574424ff79

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

describe "Matcher::Change" do
  class TestClass
    attr_reader :counter
    def initialize
      @counter = 0
    end

    def add
      @counter += 1
    end

    def dont_add; end
  end

  it 'change passes when the expected block changes the result of the argument block' do
    test_object = TestClass.new
    expect{ test_object.add }.to change{ test_object.counter }
  end

  it "change fails when the expected block doesn't change the result of the argument block" do
    test_object = TestClass.new
    expect_failure{ expect{ test_object.dont_add }.to change{ test_object.counter } }
  end

  it "change passes when the expected block doesn't change the result of the argument block but asked not_to" do
    test_object = TestClass.new
    expect{ test_object.dont_add }.not_to change{ test_object.counter }
  end

  it "change when specified 'by' passes when the expected block changes the result of the argument block by the given amount" do
    test_object = TestClass.new
    expect{ test_object.add; test_object.add }.to change{ test_object.counter }.by(2)
  end

  it "change when specified 'by' fails when the expected block changes the result of the argument block by a different amount" do
    test_object = TestClass.new
    expect_failure{ expect{ test_object.add; test_object.add }.to change{ test_object.counter }.by(6) }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bacon-expect-1.0.2 spec_app/spec/matchers/change_spec.rb
bacon-expect-1.0.1 spec_app/spec/matchers/change_spec.rb
bacon-expect-0.1 spec_app/spec/matchers/change_spec.rb