Sha256: ef03af6ace23df62097511b9e27cb3e2afd256e9d50555b968d7c0c69a9e300e

Contents?: true

Size: 1.42 KB

Versions: 43

Compression:

Stored size: 1.42 KB

Contents

require 'spec_helper'

describe "a matcher defined using the matcher DSL" do
  def question?
    :answer
  end

  def ok
    "ok"
  end

  it "supports calling custom matchers from within other custom matchers" do
    RSpec::Matchers.define :be_ok do
      match { |actual| actual == ok }
    end

    RSpec::Matchers.define :be_well do
      match { |actual| expect(actual).to be_ok }
    end

    expect(ok).to be_well
  end

  it "has access to methods available in the scope of the example" do
    RSpec::Matchers::define(:matcher_a) {}
    expect(matcher_a.question?).to eq(:answer)
  end

  it "raises when method is missing from local scope as well as matcher" do
    RSpec::Matchers::define(:matcher_b) {}
    expect { matcher_b.i_dont_exist }.to raise_error(NameError)
  end

  it "clears user instance variables between invocations" do
    RSpec::Matchers::define(:be_just_like) do |expected|
      match do |actual|
        @foo ||= expected
        @foo == actual
      end
    end

    expect(3).to be_just_like(3)
    expect(4).to be_just_like(4)
  end

  describe "#respond_to?" do
    it "returns true for methods in example scope" do
      RSpec::Matchers::define(:matcher_c) {}
      expect(matcher_c).to respond_to(:question?)
    end

    it "returns false for methods not defined in matcher or example scope" do
      RSpec::Matchers::define(:matcher_d) {}
      expect(matcher_d).not_to respond_to(:i_dont_exist)
    end
  end
end

Version data entries

43 entries across 43 versions & 12 rubygems

Version Path
tuktuk-rails-0.0.10 vendor/bundle/ruby/2.0.0/gems/rspec-expectations-2.14.4/spec/rspec/matchers/dsl_spec.rb
tuktuk-rails-0.0.9 vendor/bundle/ruby/2.0.0/gems/rspec-expectations-2.14.4/spec/rspec/matchers/dsl_spec.rb
tuktuk-rails-0.0.8 vendor/bundle/ruby/2.0.0/gems/rspec-expectations-2.14.4/spec/rspec/matchers/dsl_spec.rb
tuktuk-rails-0.0.7 vendor/bundle/ruby/2.0.0/gems/rspec-expectations-2.14.4/spec/rspec/matchers/dsl_spec.rb
dxruby_rp5-0.0.2 spec/vendor/rspec-expectations-2.14.4/spec/rspec/matchers/dsl_spec.rb
dxruby_rp5-0.0.1 spec/vendor/rspec-expectations-2.14.4/spec/rspec/matchers/dsl_spec.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/rspec-expectations-2.14.4/spec/rspec/matchers/dsl_spec.rb
rspec-expectations-3.0.0.beta1 spec/rspec/matchers/dsl_spec.rb
rspec-expectations-2.99.0.beta1 spec/rspec/matchers/dsl_spec.rb
rspec-expectations-2.14.4 spec/rspec/matchers/dsl_spec.rb
rspec-expectations-2.14.3 spec/rspec/matchers/dsl_spec.rb
clickable_link-0.0.2 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.14.2/spec/rspec/matchers/dsl_spec.rb
syllable_counter-1.0.0 vendor/bundle/gems/rspec-expectations-2.14.2/spec/rspec/matchers/dsl_spec.rb
rspec-expectations-2.14.2 spec/rspec/matchers/dsl_spec.rb
rspec-expectations-2.14.1 spec/rspec/matchers/dsl_spec.rb
rspec-expectations-2.14.0 spec/rspec/matchers/dsl_spec.rb
sshp-0.0.2 vendor/ruby/1.9.1/gems/rspec-expectations-2.13.0/spec/rspec/matchers/dsl_spec.rb
sshp-0.0.1 vendor/ruby/1.9.1/gems/rspec-expectations-2.13.0/spec/rspec/matchers/dsl_spec.rb
rspec-expectations-2.14.0.rc1 spec/rspec/matchers/dsl_spec.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/rspec-expectations-2.13.0/spec/rspec/matchers/dsl_spec.rb