Class: Webspicy::Configuration
- Inherits:
-
Object
- Object
- Webspicy::Configuration
- Defined in:
- lib/webspicy/configuration.rb,
lib/webspicy/configuration/scope.rb,
lib/webspicy/configuration/single_url.rb,
lib/webspicy/configuration/single_yml_file.rb
Defined Under Namespace
Classes: Scope, SingleUrl, SingleYmlFile
Constant Summary collapse
- LISTENER_KINDS =
[ :before_all, :before_each, :after_all, :after_each, :around_each ]
Class Attribute Summary collapse
-
.default_folder ⇒ Object
Returns the value of attribute default_folder.
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#client ⇒ Object
Returns the value of attribute client.
-
#colors ⇒ Object
Returns the value of attribute colors.
-
#errconditions ⇒ Object
readonly
Returns the value of attribute errconditions.
-
#failfast ⇒ Object
Returns the value of attribute failfast.
-
#file_filter ⇒ Object
Returns the value of attribute file_filter.
-
#folder(folder = nil, &bl) ⇒ Object
readonly
Adds a folder to the list of folders where test case definitions are to be found.
-
#generator ⇒ Object
Returns the data generator to use, for generating random data when needed.
-
#host ⇒ Object
Returns the value of attribute host.
-
#insecure ⇒ Object
Returns the value of attribute insecure.
-
#listeners(kind) ⇒ Object
readonly
Returns the listeners of a specific kind.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#postconditions ⇒ Object
readonly
Returns the value of attribute postconditions.
-
#preconditions ⇒ Object
readonly
Returns the value of attribute preconditions.
-
#rspec_options ⇒ Object
readonly
Returns the value of attribute rspec_options.
-
#run_counterexamples ⇒ Object
Returns the value of attribute run_counterexamples.
-
#run_examples ⇒ Object
Returns the value of attribute run_examples.
-
#run_generated_counterexamples ⇒ Object
Returns the value of attribute run_generated_counterexamples.
-
#scope_factory ⇒ Object
Returns the value of attribute scope_factory.
-
#service_filter ⇒ Object
Returns the value of attribute service_filter.
-
#test_case_filter ⇒ Object
Returns the value of attribute test_case_filter.
-
#world ⇒ Object
readonly
Returns the value of attribute world.
Class Method Summary collapse
Instance Method Summary collapse
-
#after_all(l = nil, &listener) ⇒ Object
Installs a listener that will be called after all tests.
-
#after_each(l = nil, &listener) ⇒ Object
Installs a listener that will be called after each web service invocation.
-
#around_each(l = nil, &listener) ⇒ Object
Installs a listener that will be called around each web service invocation.
-
#before_all(l = nil, &listener) ⇒ Object
Installs a listener that will be called before all tests.
-
#before_each(l = nil, &listener) ⇒ Object
Installs a listener that will be called before each web service invocation.
-
#data_system ⇒ Object
Returns the Data system to use for parsing schemas.
-
#default_failfast ⇒ Object
Returns the default value for failfast.
-
#default_insecure ⇒ Object
Returns the default value to use for insecure.
-
#default_test_case_filter ⇒ Object
Returns the default test case filter.
-
#dup(&bl) ⇒ Object
Duplicates this configuration and yields the block with the new one, if a block is given.
- #each_scope(&bl) ⇒ Object
-
#errcondition(clazz) ⇒ Object
Registers an errcondition matcher.
- #factor_scope ⇒ Object
-
#has_children? ⇒ Boolean
Returns whether this configuration has children configurations or not.
-
#initialize(folder = Configuration.default_folder || Path.pwd, parent = nil) {|_self| ... } ⇒ Configuration
constructor
A new instance of Configuration.
-
#instrument(&instrumentor) ⇒ Object
Installs a listener that will be called right after all precondition instrumentations.
-
#postcondition(clazz) ⇒ Object
Registers a postcondition matcher.
-
#precondition(clazz) ⇒ Object
Registers a precondition matcher.
-
#run_counterexamples? ⇒ Boolean
Whether counter examples must be ran or not.
-
#run_examples? ⇒ Boolean
Whether counter examples must be ran or not.
-
#run_generated_counterexamples? ⇒ Boolean
Whether generated counter examples must be ran or not.
Constructor Details
#initialize(folder = Configuration.default_folder || Path.pwd, parent = nil) {|_self| ... } ⇒ Configuration
Returns a new instance of Configuration.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/webspicy/configuration.rb', line 18 def initialize(folder = Configuration.default_folder || Path.pwd, parent = nil) @folder = folder. @parent = parent @children = [] @preconditions = [] @postconditions = [] @errconditions = [] @insecure = default_insecure @listeners = Hash.new{|h,k| h[k] = [] } @rspec_options = @failfast = default_failfast @run_examples = default_run_examples @run_counterexamples = default_run_counterexamples @run_generated_counterexamples = default_run_generated_counterexamples @file_filter = default_file_filter @service_filter = default_service_filter @test_case_filter = default_test_case_filter @colors = { :highlight => :cyan, :error => :red, :success => :green } @scope_factory = ->(config){ Scope.new(config) } @client = Web::HttpClient Path.require_tree(@folder/'support') if (@folder/'support').exists? @world = Support::World.new(folder/'world', self) yield(self) if block_given? end |
Class Attribute Details
.default_folder ⇒ Object
Returns the value of attribute default_folder.
7 8 9 |
# File 'lib/webspicy/configuration.rb', line 7 def default_folder @default_folder end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
131 132 133 |
# File 'lib/webspicy/configuration.rb', line 131 def children @children end |
#client ⇒ Object
Returns the value of attribute client.
327 328 329 |
# File 'lib/webspicy/configuration.rb', line 327 def client @client end |
#colors ⇒ Object
Returns the value of attribute colors.
49 50 51 |
# File 'lib/webspicy/configuration.rb', line 49 def colors @colors end |
#errconditions ⇒ Object
Returns the value of attribute errconditions.
152 153 154 |
# File 'lib/webspicy/configuration.rb', line 152 def errconditions @errconditions end |
#failfast ⇒ Object
Returns the value of attribute failfast.
407 408 409 |
# File 'lib/webspicy/configuration.rb', line 407 def failfast @failfast end |
#file_filter ⇒ Object
Returns the value of attribute file_filter.
245 246 247 |
# File 'lib/webspicy/configuration.rb', line 245 def file_filter @file_filter end |
#folder(folder = nil, &bl) ⇒ Object
Adds a folder to the list of folders where test case definitions are to be found.
115 116 117 |
# File 'lib/webspicy/configuration.rb', line 115 def folder @folder end |
#generator ⇒ Object
Returns the data generator to use, for generating random data when needed.
457 458 459 |
# File 'lib/webspicy/configuration.rb', line 457 def generator @generator end |
#host ⇒ Object
Returns the value of attribute host.
228 229 230 |
# File 'lib/webspicy/configuration.rb', line 228 def host @host end |
#insecure ⇒ Object
Returns the value of attribute insecure.
418 419 420 |
# File 'lib/webspicy/configuration.rb', line 418 def insecure @insecure end |
#listeners(kind) ⇒ Object
Returns the listeners of a specific kind.
Recognized kinds are ‘before_each`, `after_each`, `before_all`, `after_all` and `instrument`.
340 341 342 |
# File 'lib/webspicy/configuration.rb', line 340 def listeners(kind) @listeners[kind] || [] end |
#parent ⇒ Object
Returns the value of attribute parent.
93 94 95 |
# File 'lib/webspicy/configuration.rb', line 93 def parent @parent end |
#postconditions ⇒ Object
Returns the value of attribute postconditions.
145 146 147 |
# File 'lib/webspicy/configuration.rb', line 145 def postconditions @postconditions end |
#preconditions ⇒ Object
Returns the value of attribute preconditions.
138 139 140 |
# File 'lib/webspicy/configuration.rb', line 138 def preconditions @preconditions end |
#rspec_options ⇒ Object
Returns the value of attribute rspec_options.
395 396 397 |
# File 'lib/webspicy/configuration.rb', line 395 def @rspec_options end |
#run_counterexamples ⇒ Object
Returns the value of attribute run_counterexamples.
181 182 183 |
# File 'lib/webspicy/configuration.rb', line 181 def run_counterexamples @run_counterexamples end |
#run_examples ⇒ Object
Returns the value of attribute run_examples.
164 165 166 |
# File 'lib/webspicy/configuration.rb', line 164 def run_examples @run_examples end |
#run_generated_counterexamples ⇒ Object
Returns the value of attribute run_generated_counterexamples.
198 199 200 |
# File 'lib/webspicy/configuration.rb', line 198 def run_generated_counterexamples @run_generated_counterexamples end |
#scope_factory ⇒ Object
Returns the value of attribute scope_factory.
107 108 109 |
# File 'lib/webspicy/configuration.rb', line 107 def scope_factory @scope_factory end |
#service_filter ⇒ Object
Returns the value of attribute service_filter.
273 274 275 |
# File 'lib/webspicy/configuration.rb', line 273 def service_filter @service_filter end |
#test_case_filter ⇒ Object
Returns the value of attribute test_case_filter.
297 298 299 |
# File 'lib/webspicy/configuration.rb', line 297 def test_case_filter @test_case_filter end |
#world ⇒ Object (readonly)
Returns the value of attribute world.
50 51 52 |
# File 'lib/webspicy/configuration.rb', line 50 def world @world end |
Class Method Details
.dress(arg, &bl) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/webspicy/configuration.rb', line 52 def self.dress(arg, &bl) case arg when Configuration arg when /^https?:\/\// Configuration.new{|c| c.scope_factory = SingleUrl.new(arg) } when ->(f){ Path(f).exists? } arg = Path(arg) if arg.file? && arg.ext == ".rb" Configuration.with_default_folder(arg.parent) do c = Kernel.instance_eval arg.read, arg.to_s yield(c) if block_given? c end elsif arg.file? && arg.ext == '.yml' folder = arg.backfind("[config.rb]") if folder && folder.exists? dress(folder/"config.rb"){|c| c.scope_factory = SingleYmlFile.new(arg) } else Configuration.new{|c| c.scope_factory = SingleYmlFile.new(arg) } end elsif arg.directory? and (arg/'config.rb').file? dress(arg/'config.rb', &bl) else raise ArgumentError, "Missing config.rb file" end else raise ArgumentError, "Unable to turn `#{arg}` to a configuration" end end |
.inherits(*args, &bl) ⇒ Object
89 90 91 |
# File 'lib/webspicy/configuration.rb', line 89 def self.inherits(*args, &bl) dress(*args, &bl) end |
.with_default_folder(f) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/webspicy/configuration.rb', line 9 def with_default_folder(f) old = default_folder @default_folder = f yield.tap{ @default_folder = old } end |
Instance Method Details
#after_all(l = nil, &listener) ⇒ Object
Installs a listener that will be called after all tests
The ‘listener` must respond to `call`.
363 364 365 |
# File 'lib/webspicy/configuration.rb', line 363 def after_all(l = nil, &listener) register_listener(:after_all, l || listener) end |
#after_each(l = nil, &listener) ⇒ Object
Installs a listener that will be called after each web service invocation.
The ‘listener` must respond to `call`.
370 371 372 |
# File 'lib/webspicy/configuration.rb', line 370 def after_each(l = nil, &listener) register_listener(:after_each, l || listener) end |
#around_each(l = nil, &listener) ⇒ Object
Installs a listener that will be called around each web service invocation.
The ‘listener` must respond to `call`.
377 378 379 |
# File 'lib/webspicy/configuration.rb', line 377 def around_each(l = nil, &listener) register_listener(:around_each, l || listener) end |
#before_all(l = nil, &listener) ⇒ Object
Installs a listener that will be called before all tests
The ‘listener` must respond to `call`.
349 350 351 |
# File 'lib/webspicy/configuration.rb', line 349 def before_all(l = nil, &listener) register_listener(:before_all, l || listener) end |
#before_each(l = nil, &listener) ⇒ Object
Installs a listener that will be called before each web service invocation.
The ‘listener` must respond to `call`.
356 357 358 |
# File 'lib/webspicy/configuration.rb', line 356 def before_each(l = nil, &listener) register_listener(:before_each, l || listener) end |
#data_system ⇒ Object
Returns the Data system to use for parsing schemas
The data system associated with a configuration is build when the configuration folder contains a ‘schema.fio` finitio file. When no such file can be found, the parent config is checked (if any). When no `schema.fio` file can be found, the method ends up returning the default Finition system.
444 445 446 447 448 449 450 451 452 453 |
# File 'lib/webspicy/configuration.rb', line 444 def data_system schema = self.folder/"schema.fio" if schema.file? Finitio.system(schema) elsif not(self.parent.nil?) self.parent.data_system else Webspicy::DEFAULT_SYSTEM end end |
#default_failfast ⇒ Object
Returns the default value for failfast
The following environment variables <-> option are supported:
-
FAILFAST=yes <-> true
404 405 406 |
# File 'lib/webspicy/configuration.rb', line 404 def default_failfast ENV['FAILFAST'] == 'yes' || ENV['FAILFAST'] == "1" end |
#default_insecure ⇒ Object
Returns the default value to use for insecure.
The following environment variables <-> option are supported:
-
INSECURE=yes <-> true
415 416 417 |
# File 'lib/webspicy/configuration.rb', line 415 def default_insecure ENV['INSECURE'] == 'yes' || ENV['INSECURE'] == "1" end |
#default_test_case_filter ⇒ Object
Returns the default test case filter.
By default no filter is set unless a TAG environment variable is set. In that case, a test case filter is returned that filters the test cases whose tags map the specified value.
304 305 306 307 308 309 310 311 312 313 |
# File 'lib/webspicy/configuration.rb', line 304 def default_test_case_filter return nil unless = ENV['TAG'] no, yes = .split(/\s*,\s*/).partition{|t| t =~ /^!/ } no, yes = no.map{|t| t[1..-1 ]}, yes ->(tc){ (yes.empty? || !(yes & tc.).empty?) \ && \ (no.empty? || (no & tc.).empty?) } end |
#dup(&bl) ⇒ Object
Duplicates this configuration and yields the block with the new one, if a block is given.
The cloned configuration has all same values as the original but shares nothing with it. Therefore, affecting the new one has no effect on the original.
468 469 470 471 472 473 474 475 476 477 478 479 480 |
# File 'lib/webspicy/configuration.rb', line 468 def dup(&bl) super.tap do |d| d.children = [] d.preconditions = self.preconditions.dup d.postconditions = self.postconditions.dup d.errconditions = self.errconditions.dup d. = self..dup d.listeners = LISTENER_KINDS.inject({}){|ls,kind| ls.merge(kind => self.listeners(kind).dup) } yield d if block_given? end end |
#each_scope(&bl) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/webspicy/configuration.rb', line 96 def each_scope(&bl) return enum_for(:each_scope) unless block_given? if has_children? children.each do |config| config.each_scope(&bl) end else yield(factor_scope) end end |
#errcondition(clazz) ⇒ Object
Registers an errcondition matcher
149 150 151 |
# File 'lib/webspicy/configuration.rb', line 149 def errcondition(clazz) errconditions << clazz end |
#factor_scope ⇒ Object
109 110 111 |
# File 'lib/webspicy/configuration.rb', line 109 def factor_scope @scope_factory.call(self) end |
#has_children? ⇒ Boolean
Returns whether this configuration has children configurations or not
156 157 158 |
# File 'lib/webspicy/configuration.rb', line 156 def has_children? !children.empty? end |
#instrument(&instrumentor) ⇒ Object
Installs a listener that will be called right after all precondition instrumentations.
383 384 385 |
# File 'lib/webspicy/configuration.rb', line 383 def instrument(&instrumentor) register_listener(:instrument, instrumentor) end |
#postcondition(clazz) ⇒ Object
Registers a postcondition matcher
142 143 144 |
# File 'lib/webspicy/configuration.rb', line 142 def postcondition(clazz) postconditions << clazz end |
#precondition(clazz) ⇒ Object
Registers a precondition matcher
135 136 137 |
# File 'lib/webspicy/configuration.rb', line 135 def precondition(clazz) preconditions << clazz end |
#run_counterexamples? ⇒ Boolean
Whether counter examples must be ran or not.
184 185 186 |
# File 'lib/webspicy/configuration.rb', line 184 def run_counterexamples? @run_counterexamples end |
#run_examples? ⇒ Boolean
Whether counter examples must be ran or not.
167 168 169 |
# File 'lib/webspicy/configuration.rb', line 167 def run_examples? @run_examples end |
#run_generated_counterexamples? ⇒ Boolean
Whether generated counter examples must be ran or not.
201 202 203 |
# File 'lib/webspicy/configuration.rb', line 201 def run_generated_counterexamples? @run_generated_counterexamples end |