Sha256: eeef739b5f2a5fcced0d06a1eff3c0c4f29684c6e6bd1ed7b3b2ab1f2186e908

Contents?: true

Size: 1.68 KB

Versions: 189

Compression:

Stored size: 1.68 KB

Contents

RSpec::Matchers.define :map_specs do |specs|
  match do |autotest|
    @specs = specs
    @autotest = prepare(autotest)
    autotest.test_files_for(@file) == specs
  end

  chain :to do |file|
    @file = file
  end

  failure_message_for_should do
    "expected #{@autotest.class} to map #{@specs.inspect} to #{@file.inspect}\ngot #{@actual.inspect}"
  end

  def prepare(autotest)
    find_order = @specs.dup << @file
    autotest.instance_eval { @find_order = find_order }
    autotest
  end
end

RSpec::Matchers.define :fail_with do |exception_klass|
  match do |example|
    failure_reason(example, exception_klass).nil?
  end

  failure_message_for_should do |example|
    "expected example to fail with a #{exception_klass} exception, but #{failure_reason(example, exception_klass)}"
  end

  def failure_reason(example, exception_klass)
    result = example.metadata[:execution_result]
    case
      when example.metadata[:pending] then "was pending"
      when result[:status] != 'failed' then result[:status]
      when !result[:exception].is_a?(exception_klass) then "failed with a #{result[:exception].class}"
      else nil
    end
  end
end

RSpec::Matchers.define :pass do
  match do |example|
    failure_reason(example).nil?
  end

  failure_message_for_should do |example|
    "expected example to pass, but #{failure_reason(example)}"
  end

  def failure_reason(example)
    result = example.metadata[:execution_result]
    case
      when example.metadata[:pending] then "was pending"
      when result[:status] != 'passed' then result[:status]
      else nil
    end
  end
end

RSpec::Matchers.module_eval do
  alias_method :have_failed_with, :fail_with
  alias_method :have_passed, :pass
end

Version data entries

189 entries across 136 versions & 25 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rspec-core-2.14.8/spec/support/matchers.rb
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-core-2.14.8/spec/support/matchers.rb
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-core-2.14.8/spec/support/matchers.rb
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/spec/support/matchers.rb
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/spec/support/matchers.rb
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/spec/support/matchers.rb
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/spec/support/matchers.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-core-2.14.8/spec/support/matchers.rb
classiccms-0.7.5 vendor/bundle/gems/rspec-core-2.10.0/spec/support/matchers.rb
classiccms-0.7.5 vendor/bundle/gems/rspec-core-2.9.0/spec/support/matchers.rb
classiccms-0.7.4 vendor/bundle/gems/rspec-core-2.9.0/spec/support/matchers.rb
classiccms-0.7.4 vendor/bundle/gems/rspec-core-2.10.0/spec/support/matchers.rb
classiccms-0.7.3 vendor/bundle/gems/rspec-core-2.9.0/spec/support/matchers.rb
classiccms-0.7.3 vendor/bundle/gems/rspec-core-2.10.0/spec/support/matchers.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-core-2.14.8/spec/support/matchers.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rspec-core-2.13.0/spec/support/matchers.rb
rspec-core-2.99.2 spec/support/matchers.rb
dxruby_rp5-0.0.4 spec/vendor/rspec-core-2.14.7/spec/support/matchers.rb
rspec-core-2.99.1 spec/support/matchers.rb
rspec-core-2.99.0 spec/support/matchers.rb