Class: Webspicy::Configuration::Scope

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Scope

Returns a new instance of Scope.



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

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

Instance Method Details

#data_systemObject

Returns the Data system to use for parsing schemas



99
100
101
# File 'lib/webspicy/configuration/scope.rb', line 99

def data_system
  @data_system ||= config.data_system
end

#each_counterexamples(service, &bl) ⇒ Object



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

def each_counterexamples(service, &bl)
  service.counterexamples
    .map{|e| expand_example(service, e) }
    .select(&to_filter_proc(config.test_case_filter))
    .each(&bl) if config.run_counterexamples?
end

#each_example(service, &bl) ⇒ Object



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

def each_example(service, &bl)
  service.examples
    .map{|e| expand_example(service, e) }
    .select(&to_filter_proc(config.test_case_filter))
    .each(&bl) if config.run_examples?
end

#each_generated_counterexamples(service, &bl) ⇒ Object



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

def each_generated_counterexamples(service, &bl)
  Webspicy.with_scope(self) do
    service.generated_counterexamples
      .map{|e| expand_example(service, e) }
      .select(&to_filter_proc(config.test_case_filter))
      .each(&bl) if config.run_generated_counterexamples?
  end if config.run_generated_counterexamples?
end

#each_service(specification, &bl) ⇒ Object



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

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

#each_specification(apply_filter = true, &bl) ⇒ Object

Yields each specification in the current scope in turn.



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

def each_specification(apply_filter = true, &bl)
  return enum_for(:each_specification, apply_filter) unless block_given?
  each_specification_file(apply_filter) do |file, folder|
    yield config.factory.specification(file.load, file, self)
  end
end

#each_specification_file(apply_filter = true, &bl) ⇒ Object

Yields each specification file in the current scope



15
16
17
18
# File 'lib/webspicy/configuration/scope.rb', line 15

def each_specification_file(apply_filter = true, &bl)
  return enum_for(:each_specification_file, apply_filter) unless block_given?
  _each_specification_file(config, apply_filter, &bl)
end

#each_testcase(service, &bl) ⇒ Object



71
72
73
74
75
# File 'lib/webspicy/configuration/scope.rb', line 71

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

#find_test_case(method, url) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/webspicy/configuration/scope.rb', line 77

def find_test_case(method, url)
  each_specification(false) do |spec|
    next unless spec.url == url
    spec.services.each do |service|
      next unless service.method == method
      return service.examples.first
    end
  end
  nil
end

#get_clientObject

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



110
111
112
# File 'lib/webspicy/configuration/scope.rb', line 110

def get_client
  config.client.new(self)
end

#parse_schema(fio) ⇒ Object

Parses a Finitio schema based on the data system.



94
95
96
# File 'lib/webspicy/configuration/scope.rb', line 94

def parse_schema(fio)
  data_system.parse(fio)
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.



120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/webspicy/configuration/scope.rb', line 120

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