Sha256: aeaa363f4ac595815eb48bae9cd9f0f91ad9732217b8102606267ce36e1d4981

Contents?: true

Size: 1.43 KB

Versions: 20

Compression:

Stored size: 1.43 KB

Contents

# RSpec matcher to spec delegations.

RSpec::Matchers.define :raise_rescue_response_type do |expected_rescue_response|
  match do |response|
    @expected_rescue_response = expected_rescue_response.to_sym
    @exception = nil

    begin
      @status = response.call.status
    rescue Exception => e
      @exception = e
    end

    if @exception.nil?
      @actual_rescue_response = @status
      @status == Rack::Utils.status_code(@expected_rescue_response)
    else
      response = ActionDispatch::ExceptionWrapper.rescue_responses[@exception.class.name]
      @actual_rescue_response = ActionDispatch::ExceptionWrapper.rescue_responses[@exception.class.name].to_sym
      @actual_rescue_response == @expected_rescue_response
    end
  end

  description do
    "expected to raise an exception with rescue_response #{@expected_rescue_response.inspect}"
  end

  failure_message_for_should do |text|
    text = "expected to raise an exception with rescue_response"
    text << " #{@expected_rescue_response.inspect} instead got #{@actual_rescue_response.inspect}"
    text << " (Exception #{@exception.class}: #{@exception})" if @exception
    text
  end

  failure_message_for_should_not do |text|
    text = "expected to NOT raise an exception with rescue_response"
    text << " #{@expected_rescue_response.inspect} but got #{@actual_rescue_response.inspect}"
    text << " (Exception #{@exception.class}: #{@exception})" if @exception
    text
  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
curate-0.6.6 spec/matchers/raise_rescue_response_type_matcher.rb
curate-0.6.5 spec/matchers/raise_rescue_response_type_matcher.rb
curate-0.6.4 spec/matchers/raise_rescue_response_type_matcher.rb
curate-0.6.3 spec/matchers/raise_rescue_response_type_matcher.rb
curate-0.6.1 spec/support/matchers/raise_rescue_response_type_matcher.rb
curate-0.6.0 spec/support/matchers/raise_rescue_response_type_matcher.rb
curate-0.5.6 spec/support/matchers/raise_rescue_response_type_matcher.rb
curate-0.5.5 spec/support/matchers/raise_rescue_response_type_matcher.rb
curate-0.5.4 spec/support/matchers/raise_rescue_response_type_matcher.rb
curate-0.5.2 spec/support/matchers/raise_rescue_response_type_matcher.rb
curate-0.5.1 spec/support/matchers/raise_rescue_response_type_matcher.rb
curate-0.5.0 spec/support/matchers/raise_rescue_response_type_matcher.rb
curate-0.4.2 spec/support/matchers/raise_rescue_response_type_matcher.rb
curate-0.3.2 spec/support/matchers/raise_rescue_response_type_matcher.rb
curate-0.3.1 spec/support/matchers/raise_rescue_response_type_matcher.rb
curate-0.2.0 spec/support/matchers/raise_rescue_response_type_matcher.rb
curate-0.1.3 spec/support/matchers/raise_rescue_response_type_matcher.rb
curate-0.1.2 spec/support/matchers/raise_rescue_response_type_matcher.rb
curate-0.1.1 spec/support/matchers/raise_rescue_response_type_matcher.rb
curate-0.1.0 spec/support/matchers/raise_rescue_response_type_matcher.rb