Module: ActiveResourceHttpMock::RSpec

Defined in:
lib/active_resource_http_mock/rspec.rb

Class Method Summary collapse

Class Method Details

.configureObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/active_resource_http_mock/rspec.rb', line 9

def configure
  ::RSpec.configure do |config|
    config.include self

    config.around :each do |example|
      if (context = example.[:httpmock]) && example.[:js].blank?
        data = ActiveResourceHttpMock::DataFile.new(context)

        if data.load_mocks
          enable_http_mock
          begin
            example.run
          ensure
            disable_http_mock
          end
        else
          ActiveResourceHttpMock::LogSubscriber.events.clear
          example.run
          data.dump_mocks ActiveResourceHttpMock::LogSubscriber.responses unless @example.exception
        end
      else
        example.run
      end
    end
  end
end