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



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

def data_system
  @data_system ||= config.data_system
end

#each_counterexamples(service, &bl) ⇒ Object



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

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



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

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



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

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



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

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.



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

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 Webspicy.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



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

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



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

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



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

def get_client
  config.client.new(self)
end

#parse_schema(fio) ⇒ Object

Parses a Finitio schema based on the data system.



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

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.



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

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