Sha256: 39831fbe0e02cb98114c6a633754c7ff388235b99158c27d42f40081de084f97

Contents?: true

Size: 1.92 KB

Versions: 16

Compression:

Stored size: 1.92 KB

Contents

require 'spec_helper'

module RSpec
  module Expectations
    # so our examples below can set expectations about the target
    ExpectationTarget.send(:attr_reader, :target)

    describe ExpectationTarget do
      context 'when constructed via #expect' do
        it 'constructs a new instance targetting the given argument' do
          expect(7).target.should eq(7)
        end

        it 'constructs a new instance targetting the given block' do
          block = lambda {}
          expect(&block).target.should be(block)
        end

        it 'raises an ArgumentError when given an argument and a block' do
          lambda { expect(7) { } }.should raise_error(ArgumentError)
        end

        it 'raises an ArgumentError when given neither an argument nor a block' do
          lambda { expect }.should raise_error(ArgumentError)
        end

        it 'can be passed nil' do
          expect(nil).target.should be_nil
        end

        it 'passes a valid positive expectation' do
          expect(5).to eq(5)
        end

        it 'passes a valid negative expectation' do
          expect(5).to_not eq(4)
          expect(5).not_to eq(4)
        end

        it 'fails an invalid positive expectation' do
          lambda { expect(5).to eq(4) }.should fail_with(/expected: 4.*got: 5/m)
        end

        it 'fails an invalid negative expectation' do
          message = /expected 5 not to be a kind of Fixnum/
          lambda { expect(5).to_not be_a(Fixnum) }.should fail_with(message)
          lambda { expect(5).not_to be_a(Fixnum) }.should fail_with(message)
        end

        it 'does not support operator matchers from #to' do
          expect {
            expect(3).to == 3
          }.to raise_error(ArgumentError)
        end

        it 'does not support operator matchers from #not_to' do
          expect {
            expect(3).not_to == 4
          }.to raise_error(ArgumentError)
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 6 rubygems

Version Path
tnargav-1.3.3 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.11.3/spec/rspec/expectations/expectation_target_spec.rb
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.11.3/spec/rspec/expectations/expectation_target_spec.rb
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/rspec-expectations-2.12.1/spec/rspec/expectations/expectation_target_spec.rb
remq-0.0.4 vendor/bundle/gems/rspec-expectations-2.12.1/spec/rspec/expectations/expectation_target_spec.rb
remq-0.0.3 vendor/bundle/gems/rspec-expectations-2.12.1/spec/rspec/expectations/expectation_target_spec.rb
librarian-puppet-0.9.8 vendor/gems/ruby/1.9.1/gems/rspec-expectations-2.12.1/spec/rspec/expectations/expectation_target_spec.rb
rspec-expectations-2.12.1 spec/rspec/expectations/expectation_target_spec.rb
rspec-expectations-2.12.0 spec/rspec/expectations/expectation_target_spec.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.11.3/spec/rspec/expectations/expectation_target_spec.rb
gem_repackager-0.1.0 support/gems/rspec-expectations-2.11.2/spec/rspec/expectations/expectation_target_spec.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/rspec-expectations-2.11.2/spec/rspec/expectations/expectation_target_spec.rb
rspec-expectations-2.11.3 spec/rspec/expectations/expectation_target_spec.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/rspec-expectations-2.11.2/spec/rspec/expectations/expectation_target_spec.rb
rspec-expectations-2.11.2 spec/rspec/expectations/expectation_target_spec.rb
rspec-expectations-2.11.1 spec/rspec/expectations/expectation_target_spec.rb
rspec-expectations-2.11.0 spec/rspec/expectations/expectation_target_spec.rb