class Webspicy::Configuration::Scope

Attributes

config[R]

Public Class Methods

new(config) click to toggle source
# File lib/webspicy/configuration/scope.rb, line 5
def initialize(config)
  @config = config
end

Public Instance Methods

data_system() click to toggle source

Returns the Data system to use for parsing schemas

# File lib/webspicy/configuration/scope.rb, line 97
def data_system
  @data_system ||= config.data_system
end
each_counterexamples(service, &bl) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) { |factory.specification(load, file, self)| ... } click to toggle source

Yields each specification in the current scope in turn.

# 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) click to toggle source

Yields each specification file in the current scope

# 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) click to toggle source
# 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) click to toggle source
# 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_client() click to toggle source

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

# File lib/webspicy/configuration/scope.rb, line 108
def get_client
  config.client.new(self)
end
parse_schema(fio) click to toggle source

Parses a Finitio schema based on the data system.

# File lib/webspicy/configuration/scope.rb, line 92
def parse_schema(fio)
  data_system.parse(fio)
end
to_real_url(url, test_case = nil) { |url| ... } click to toggle source

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.

# 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

Private Instance Methods

_each_specification_file(config, apply_filter = true) { |file, folder| ... } click to toggle source

Recursive implementation of `each_specification_file` for each folder in the configuration.

# File lib/webspicy/configuration/scope.rb, line 22
def _each_specification_file(config, apply_filter = true)
  folder = config.folder
  world  = config.folder/"world"
  fs = folder.glob("**/*.{yml, yaml}").reject{|f| f.to_s.start_with?(world.to_s) }
  fs = fs.sort
  fs = fs.select(&to_filter_proc(config.file_filter)) if apply_filter
  fs.each do |file|
    yield file, folder
  end
end
expand_example(service, example) click to toggle source

Private methods

# File lib/webspicy/configuration/scope.rb, line 137
def expand_example(service, example)
  return example unless service.default_example
  h1 = service.default_example.to_info
  h2 = example.to_info
  ex = config.factory.test_case(merge_maps(h1, h2), self)
  ex.bind(service, example.counterexample?)
end
merge_maps(h1, h2) click to toggle source
# File lib/webspicy/configuration/scope.rb, line 145
def merge_maps(h1, h2)
  h1.merge(h2) do |k,v1,v2|
    case v1
    when Hash  then merge_maps(v1, v2)
    when Array then v1 + v2
    else v2
    end
  end
end
to_filter_proc(filter) click to toggle source

Returns a proc that implements file_filter strategy according to the type of filter installed

# File lib/webspicy/configuration/scope.rb, line 157
def to_filter_proc(filter)
  case ff = filter
  when NilClass then ->(f){ true }
  when Proc     then ff
  when Regexp   then ->(f){ ff =~ f.to_s }
  else
    ->(f){ ff === f }
  end
end