Module: SerialSpec::ClassMethods

Defined in:
lib/serial_spec.rb

Instance Method Summary collapse

Instance Method Details

#with_request(request_str, params = {}, envs = {}, &block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/serial_spec.rb', line 34

def with_request(request_str, params={}, envs={}, &block)
  if request_str.split(/\s+/).count == 2
    request_method_string, request_path_str = request_str.split(/\s+/)
  end

  context_klass = context "with request: '#{request_str}'" do
    if request_str.split(/\s+/).count == 2
      request_method_string, request_path_str = request_str.split(/\s+/)
      if SERIAL_VALID_VERBS.include?(request_method_string)
        # Prefer preference to blocks, chances are the blocks need to be
        # executed at a lower level
        unless request_opts[:request_method] and request_opts[:request_method].instance_of?(InheritableAccessors::InheritableOptionAccessor::LetOption)
          request_method request_method_string
        end

        unless request_opts[:request_path] and request_opts[:request_path].instance_of?(InheritableAccessors::InheritableOptionAccessor::LetOption)
          request_path   request_path_str
        end
      end
    end

    instance_exec(&block) if block_given?

    it "should match all examples: #{__inherited_expectations__.keys}" do
      perform_request!
    end

  end

end