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
pivotal-screw-unit-server-0.5.6 vendor/js-test-core/spec/spec_helpers/be_http.rb
pivotal-screw-unit-server-0.5.6 vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb
pivotal-screw-unit-server-0.5.7 vendor/js-test-core/spec/spec_helpers/be_http.rb
pivotal-screw-unit-server-0.5.7 vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb
pivotal-screw-unit-server-0.5.8 vendor/js-test-core/spec/spec_helpers/be_http.rb
pivotal-screw-unit-server-0.5.8 vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb
pivotal-screw-unit-server-0.5.9 vendor/js-test-core/spec/spec_helpers/be_http.rb
pivotal-screw-unit-server-0.5.9 vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb
honkster-js-test-server-0.2.12 spec/spec_helpers/be_http.rb
honkster-js-test-server-0.2.12 vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb
honkster-js-test-server-0.2.11 vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb
honkster-js-test-server-0.2.11 spec/spec_helpers/be_http.rb
honkster-js-test-server-0.2.10 spec/spec_helpers/be_http.rb
honkster-js-test-server-0.2.10 vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb
honkster-js-test-server-0.2.9 vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb
honkster-js-test-server-0.2.9 spec/spec_helpers/be_http.rb
honkster-screw-unit-server-0.6.3 vendor/js-test-core/vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb
honkster-screw-unit-server-0.6.3 vendor/js-test-core/spec/spec_helpers/be_http.rb
js-test-server-0.2.8 vendor/lucky-luciano/lib/lucky_luciano/rspec/be_http.rb
js-test-server-0.2.8 spec/spec_helpers/be_http.rb