Module: RSpec::Httpd
- Extended by:
- Httpd
- Includes:
- Expectation
- Included in:
- Httpd
- Defined in:
- lib/rspec/httpd/version.rb,
lib/rspec/httpd/server.rb,
lib/rspec/httpd/client.rb,
lib/rspec/httpd.rb,
lib/rspec/httpd.rb
Defined Under Namespace
Modules: GemHelper, Server Classes: Client
Constant Summary collapse
- VERSION =
GemHelper.version "rspec-httpd"
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#client(host:, port:, command: nil) ⇒ Object
builds and returns a client.
-
#configure(&block) ⇒ Object
Set the configuration for the default client.
- #expect_response(expected = nil, status: nil, client: nil) ⇒ Object
-
#logger ⇒ Object
:nodoc:.
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
17 18 19 |
# File 'lib/rspec/httpd.rb', line 17 def config @config end |
Instance Method Details
#client(host:, port:, command: nil) ⇒ Object
builds and returns a client.
You can use this method to retrieve a client connection to a server specified via host:, port:, and, optionally, a command.
34 35 36 37 38 39 40 |
# File 'lib/rspec/httpd.rb', line 34 def client(host:, port:, command: nil) @clients ||= {} @clients[[host, port, command]] ||= begin Server.start!(host: host, port: port, command: command) if command Client.new host: host, port: port end end |
#configure(&block) ⇒ Object
Set the configuration for the default client.
See also: RSpec::Httpd.http
22 23 24 |
# File 'lib/rspec/httpd.rb', line 22 def configure(&block) @config = Config.new.tap(&block) end |
#expect_response(expected = nil, status: nil, client: nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rspec/httpd.rb', line 56 def expect_response(expected = nil, status: nil, client: nil) client ||= http # only check status? This lets us write # # expect_response 201 # if expected.is_a?(Integer) && status.nil? expect(client.status).to eq(expected) return end # do_expect_last_request is implemented in RSpec::Httpd::Expectation, and mixed in # here, because it needs access to the expect() implementation. expect(client.status).to eq(status || 200) unless expected.nil? do_expect_last_request(expected: expected, client: client) end end |
#logger ⇒ Object
:nodoc:
26 27 28 |
# File 'lib/rspec/httpd.rb', line 26 def logger #:nodoc: @logger ||= Logger.new(STDERR).tap { |logger| logger.level = Logger::INFO } end |