Sha256: c8f4fc61733997d3949bb0dbeaff2eb8ba847c6ed80bf813fe53bc048eafce4b

Contents?: true

Size: 944 Bytes

Versions: 58

Compression:

Stored size: 944 Bytes

Contents

module BeHttp
  include Spec::Matchers
  def be_http(status, headers, body)
    SimpleMatcher.new(nil) do |given, matcher|
      description = (<<-DESC).gsub(/^ +/, "")
      be an http of
      expected status: #{status.inspect}
      actual status  : #{given.status.inspect}

      expected headers containing: #{headers.inspect}
      actual headers             : #{given.headers.inspect}

      expected body containing: #{body.inspect}
      actual body             : #{given.body.inspect}
      DESC
      matcher.failure_message = description
      matcher.negative_failure_message = "not #{description}"

      passed = true
      unless given.status == status
        passed = false
      end
      unless headers.all?{|k, v| given.headers[k] == headers[k]}
        passed = false
      end
      unless body.is_a?(Regexp) ? given.body =~ body : given.body.include?(body)
        passed = false
      end
      passed
    end
  end
end

Version data entries

58 entries across 30 versions & 8 rubygems

Version Path
js-test-server-0.2.7 vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb
js-test-server-0.2.7 spec/spec_helpers/be_http.rb
js-test-server-0.2.6 vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb
js-test-server-0.2.6 spec/spec_helpers/be_http.rb
js-test-server-0.2.1 spec/spec_helpers/be_http.rb
js-test-server-0.2.0 spec/spec_helpers/be_http.rb
honkster-screw-unit-server-0.6.2 vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb
honkster-screw-unit-server-0.6.2 vendor/js-test-core/spec/spec_helpers/be_http.rb
honkster-screw-unit-server-0.6.1 vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb
honkster-screw-unit-server-0.6.1 vendor/js-test-core/spec/spec_helpers/be_http.rb
btakita-screw-unit-server-0.6.0 vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb
btakita-screw-unit-server-0.6.0 vendor/js-test-core/spec/spec_helpers/be_http.rb
screw-unit-0.5.1 vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb
screw-unit-0.5.1 vendor/js-test-core/spec/spec_helpers/be_http.rb
screw-unit-0.5.2 vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb
screw-unit-server-0.5.3 vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb
screw-unit-0.5.2 vendor/js-test-core/spec/spec_helpers/be_http.rb
screw-unit-server-0.5.3 vendor/js-test-core/spec/spec_helpers/be_http.rb