Module: RSpec::Apib

Defined in:
lib/rspec/apib.rb,
lib/rspec/apib/writer.rb,
lib/rspec/apib/version.rb,
lib/rspec/apib/recorder.rb,
lib/rspec/apib/configuration.rb,
lib/rspec/apib/comments_parser.rb

Defined Under Namespace

Classes: CommentsParser, Configuration, Recorder, Writer

Constant Summary collapse

VERSION =
"1.1.0"

Class Method Summary collapse

Class Method Details

.configObject



17
18
19
# File 'lib/rspec/apib.rb', line 17

def config
  @config || configure
end

.configure {|@config| ... } ⇒ Object

Yields:



11
12
13
14
15
# File 'lib/rspec/apib.rb', line 11

def configure
  @config = Configuration.new
  yield(@config) if block_given?
  @config
end

.connectionObject



21
22
23
# File 'lib/rspec/apib.rb', line 21

def connection
  Connection.instance
end

.record(example, request, response, routes) ⇒ Object



39
40
41
42
43
# File 'lib/rspec/apib.rb', line 39

def record(example, request, response, routes)
  @_doc ||= {}
  recorder = Recorder.new(example, request, response, routes, @_doc)
  recorder.run
end

.record?(example) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
# File 'lib/rspec/apib.rb', line 50

def record?(example)
  default_recording_policy = config.default_recording_policy
  config.record_types.include?(example.[:type]) &&
    (
      default_recording_policy && !(example.[:apib] === false) ||
      !default_recording_policy && (example.[:apib] === true)
    )
end

.startObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rspec/apib.rb', line 25

def start
  RSpec.configure do |config|
    config.after :each do |example|
      if RSpec::Apib.record?(example)
        RSpec::Apib.record(example, request, response, @routes)
      end
    end

    config.after :all do |example|
      RSpec::Apib.write
    end
  end
end

.writeObject



45
46
47
48
# File 'lib/rspec/apib.rb', line 45

def write
  writer = Writer.new(@_doc || {})
  writer.write
end