28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/irumugam/spec_writer.rb', line 28
def self.create_example_groups
ServiceRegistry.instance.services.values.each do |service|
eg = RSpec::Core::ExampleGroup.describe("#{service.name} specs") do
before :all, &(service.before_blocks[:all]) if service.before_blocks[:all]
before :each, &(service.before_blocks[:each]) if service.before_blocks[:each]
after :all, &(service.after_blocks[:all]) if service.after_blocks[:all]
after :each, &(service.after_blocks[:each]) if service.after_blocks[:each]
ServiceRegistry.instance.paths_for(service.name).each do |contract|
it "#{contract.method} #{contract.path} should return with #{contract.contract_status}" do
path_object = self.instance_eval(&contract.path_object_block) if contract.path_object_block
response = contract.perform_request(:path_object=>path_object)
response.code.should==contract.contract_status
contract.prepare_response(response.body).should == contract.json_for_spec if contract.contract_json
response.body.should == contract.contract_body if contract.contract_body
end
end
end
eg.register
end
end
|