Top Level Namespace

Defined Under Namespace

Modules: Angus, HtmlRender, JsonRender Classes: MiddlewareNotFound, OperationResponse, Thor

Instance Method Summary collapse

Instance Method Details

#describe_operation(operation, service, &block) ⇒ Object

Describes an operation

Builds a describe block that:

  • includes Rack::Test::Methods

  • defines app method that returns the service

  • defines response method

Parameters:

  • operation

    the operation being specified, ex: GET /profiles

  • service

    the Service (rack app) that exposes the operation



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
64
# File 'lib/angus/rspec/support/examples.rb', line 14

def describe_operation(operation, service, &block)

  describe(operation) do
    include Rack::Test::Methods

    define_method :app do
      service
    end

    define_method :method_missing do |m, *args, &block|
      if m.to_s =~ /_path$/
	      service.public_send m, *args, &block
      else
	      super(m, *args, &block)
      end
    end

    def response
      if @response && @response.wraps?(last_response)
        return @response
      else
        @response = OperationResponse.new(last_response)
      end
    end


    define_singleton_method :describe_errors do |errors_spec|
      errors_spec.each do |e, status_code|

        __caller = caller[2..-1]
        it "raises #{e} with status = #{status_code}", :caller => __caller do

          Angus::RSpec::Examples::DescribeErrors.mock_service(service, e, self) do
            get '/'

            if response.http_status_code != status_code
              e = RSpec::Expectations::ExpectationNotMetError.new(
                "Expected status: #{status_code}, got: #{response.http_status_code}"
              )
              e.set_backtrace(__caller)
              raise e
            end
          end

        end
      end
    end

    instance_eval(&block)
  end
end