Class: Rack::ClientSpec::TestCase
- Inherits:
-
Object
- Object
- Rack::ClientSpec::TestCase
- Includes:
- Assertions
- Defined in:
- lib/rack/client_spec/test_case.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#sequence ⇒ Object
readonly
Returns the value of attribute sequence.
Class Method Summary collapse
Instance Method Summary collapse
- #assert_request(expect_request, &block) ⇒ Object
- #call_test_method(name, test: nil) ⇒ Object
-
#initialize(got_sequence = nil) ⇒ TestCase
constructor
A new instance of TestCase.
- #route(method, path, env, &block) ⇒ Object
Methods included from Assertions
Constructor Details
#initialize(got_sequence = nil) ⇒ TestCase
Returns a new instance of TestCase.
31 32 33 34 35 |
# File 'lib/rack/client_spec/test_case.rb', line 31 def initialize(got_sequence = nil) @got_sequence = got_sequence @run_test = !got_sequence.nil? @sequence = [] end |
Instance Attribute Details
#sequence ⇒ Object (readonly)
Returns the value of attribute sequence.
29 30 31 |
# File 'lib/rack/client_spec/test_case.rb', line 29 def sequence @sequence end |
Class Method Details
.make_sequences ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/rack/client_spec/test_case.rb', line 11 def self.make_sequences() sequences = {} self.instance_methods.grep(/^test_/).map do |name| sequences[name] = self.new(nil).call_test_method(name, test: false).sequence end sequences end |
Instance Method Details
#assert_request(expect_request, &block) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/rack/client_spec/test_case.rb', line 37 def assert_request(expect_request, &block) got = @got_sequence.shift unless expect_request.match? got.env raise ArgumentError, "Request is not matched with the expected request" end block.yield got.env, got.response end |
#call_test_method(name, test: nil) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/rack/client_spec/test_case.rb', line 45 def call_test_method(name, test: nil) @run_test = test unless test.nil? setup if respond_to? :setup send name self end |
#route(method, path, env, &block) ⇒ Object
52 53 54 55 56 |
# File 'lib/rack/client_spec/test_case.rb', line 52 def route(method, path, env, &block) request = ExpectRequest.new(method, path, env) @sequence << request assert_request request, &block if @run_test end |