Class: Webspicy::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/webspicy/scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Scope

Returns a new instance of Scope.



4
5
6
# File 'lib/webspicy/scope.rb', line 4

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/webspicy/scope.rb', line 7

def config
  @config
end

Instance Method Details

#data_systemObject

Returns the Data system to use for parsing schemas



86
87
88
# File 'lib/webspicy/scope.rb', line 86

def data_system
  @data_system ||= config.data_system
end

#each_counterexamples(service, &bl) ⇒ Object



55
56
57
58
59
# File 'lib/webspicy/scope.rb', line 55

def each_counterexamples(service, &bl)
  service.counterexamples.each{|e|
    yield(expand_example(service, e), true)
  } if config.run_counterexamples?
end

#each_example(service) ⇒ Object



49
50
51
52
53
# File 'lib/webspicy/scope.rb', line 49

def each_example(service)
  service.examples.each{|e|
    yield(expand_example(service, e), false)
  }
end

#each_generated_counterexamples(service, &bl) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/webspicy/scope.rb', line 61

def each_generated_counterexamples(service, &bl)
  Webspicy.with_scope(self) do
    service.generated_counterexamples.each{|e|
      yield(expand_example(service, e), true)
    }
  end if config.run_counterexamples?
end

#each_resource(&bl) ⇒ Object

Yields each resource in the current scope in turn.



38
39
40
41
42
43
# File 'lib/webspicy/scope.rb', line 38

def each_resource(&bl)
  return enum_for(:each_resource) unless block_given?
  each_resource_file do |file, folder|
    yield Webspicy.resource(file.load, file, self)
  end
end

#each_resource_file(&bl) ⇒ Object

Yields each resource file in the current scope



22
23
24
25
# File 'lib/webspicy/scope.rb', line 22

def each_resource_file(&bl)
  return enum_for(:each_resource_file) unless block_given?
  _each_resource_file(config, &bl)
end

#each_service(resource, &bl) ⇒ Object



45
46
47
# File 'lib/webspicy/scope.rb', line 45

def each_service(resource, &bl)
  resource.services.select(&to_filter_proc(config.service_filter)).each(&bl)
end

#each_testcase(service, &bl) ⇒ Object



69
70
71
72
73
# File 'lib/webspicy/scope.rb', line 69

def each_testcase(service, &bl)
  each_example(service, &bl)
  each_counterexamples(service, &bl)
  each_generated_counterexamples(service, &bl)
end

#get_clientObject

Returns an instance of the client to use to invoke web services



97
98
99
# File 'lib/webspicy/scope.rb', line 97

def get_client
  config.client.new(self)
end

#parse_schema(fio) ⇒ Object

Parses a Finitio schema based on the data system.



81
82
83
# File 'lib/webspicy/scope.rb', line 81

def parse_schema(fio)
  data_system.parse(fio)
end

#postconditionsObject



13
14
15
# File 'lib/webspicy/scope.rb', line 13

def postconditions
  config.postconditions
end

#preconditionsObject



9
10
11
# File 'lib/webspicy/scope.rb', line 9

def preconditions
  config.preconditions
end

#to_real_url(url, test_case = nil, &bl) ⇒ Object

Convert an instantiated URL found in a webservice definition to a real URL, using the configuration host.

When no host resolved on the configuration and the url is not already an absolute URL, yields the block if given, or raise an exception.



107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/webspicy/scope.rb', line 107

def to_real_url(url, test_case = nil, &bl)
  case config.host
  when Proc
    config.host.call(url, test_case)
  when String
    url =~ /^http/ ? url : "#{config.host}#{url}"
  else
    return url if url =~ /^http/
    return yield(url) if block_given?
    raise "Unable to resolve `#{url}` : no host resolver provided\nSee `Configuration#host="
  end
end