Sha256: 803c4d7a50eb22f87aeb4c0011d23a6f36f7d6e888c9e6fa354173b9c82c691f

Contents?: true

Size: 1.01 KB

Versions: 23

Compression:

Stored size: 1.01 KB

Contents

RSpec::Matchers.define :succeed_on do |input|
  match do |operation|
    @operation, @input = operation, input

    success? && return_value_matches?
  end

  match_when_negated do |operation|
    raise NotImplementedError, '`expect().not_to succeed_on(input).returning()` is not supported.' if @value
    @operation, @input = operation, input

    !success?
  end

  chain :returning do |value|
    @value = value
  end

  description do
    "be successful"
  end

  failure_message do
    if !success?
      "Expected operation to be successful but failed with :#{result.error.type} error"
    else
      "Expected successful operation to return #{description_of(@value)} but instead got #{description_of(result.value)}"
    end
  end

  failure_message_when_negated do
    "Did not to expected operation to be successful but it was"
  end

  def success?
    result.success?
  end

  def return_value_matches?
    @value.nil? || values_match?(@value, result.value)
  end

  def result
    @result ||= @operation.call(@input)
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
pathway-0.10.0 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.9.1 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.9.0 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.8.0 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.7.0 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.6.2 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.6.1 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.6.0 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.5.1 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.5.0 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.4.0 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.0.20 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.0.19 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.0.18 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.0.17 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.0.16 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.0.15 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.0.14 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.0.13 lib/pathway/rspec/matchers/succeed_on.rb
pathway-0.0.12 lib/pathway/rspec/matchers/succeed_on.rb