Class: ApiPi::Dsl

Inherits:
Object show all
Defined in:
lib/api_pi/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Dsl

Returns a new instance of Dsl.



8
9
10
11
# File 'lib/api_pi/dsl.rb', line 8

def initialize response
  @tests = {}
  @response = Map.new(response)
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/api_pi/dsl.rb', line 6

def response
  @response
end

#testsObject (readonly)

Returns the value of attribute tests.



6
7
8
# File 'lib/api_pi/dsl.rb', line 6

def tests
  @tests
end

Instance Method Details

#parse(url, block) ⇒ Object



13
14
15
16
17
# File 'lib/api_pi/dsl.rb', line 13

def parse url, block
  self.instance_eval(&block)
  pi = ApiPi::Case.new(url, tests)
  pi.investigate
end

#test(desc, &block) ⇒ Object

Test blocks are used to group similar assertions into readable units.

For example, you may want to put your header tests into one test block:

get 'example.com/user.json' do
  test 'Headers have correct data' do
    # You header assertions...
  end
end

Inside of the test block, you would then put your header assertions. onceyou run your tests, your test blocks are grouped together and pass/fail based on assertions in the test block.



33
34
35
# File 'lib/api_pi/dsl.rb', line 33

def test desc, &block
  @tests[desc] = block
end