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



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

def data_system
  @data_system ||= config.data_system
end

#each_counterexamples(service, &bl) ⇒ Object



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

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



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

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



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

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



42
43
44
# File 'lib/webspicy/configuration/scope.rb', line 42

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.



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

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



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

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



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

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



108
109
110
# File 'lib/webspicy/configuration/scope.rb', line 108

def get_client
  config.client.new(self)
end

#parse_schema(fio) ⇒ Object

Parses a Finitio schema based on the data system.



92
93
94
# File 'lib/webspicy/configuration/scope.rb', line 92

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.



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

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