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.
-
#colorize ⇒ Object
Returns the value of attribute colorize.
-
#colors ⇒ Object
Returns the value of attribute colors.
-
#errconditions ⇒ Object
readonly
Returns the value of attribute errconditions.
-
#factory ⇒ Object
Returns the value of attribute factory.
-
#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.
-
#reporter ⇒ Object
Returns the value of attribute reporter.
-
#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_reporter ⇒ Object
Returns the default reporter to use.
-
#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 46 47 48 49 |
# 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 = { :section => :magenta, :highlight => :cyan, :error => :red, :success => :green } @colorize = true @factory = Webspicy::Web @scope_factory = ->(config){ Scope.new(config) } @client = Web::HttpClient @reporter = default_reporter 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.
138 139 140 |
# File 'lib/webspicy/configuration.rb', line 138 def children @children end |
#client ⇒ Object
Returns the value of attribute client.
334 335 336 |
# File 'lib/webspicy/configuration.rb', line 334 def client @client end |
#colorize ⇒ Object
Returns the value of attribute colorize.
54 55 56 |
# File 'lib/webspicy/configuration.rb', line 54 def colorize @colorize end |
#colors ⇒ Object
Returns the value of attribute colors.
53 54 55 |
# File 'lib/webspicy/configuration.rb', line 53 def colors @colors end |
#errconditions ⇒ Object
Returns the value of attribute errconditions.
159 160 161 |
# File 'lib/webspicy/configuration.rb', line 159 def errconditions @errconditions end |
#factory ⇒ Object
Returns the value of attribute factory.
113 114 115 |
# File 'lib/webspicy/configuration.rb', line 113 def factory @factory end |
#failfast ⇒ Object
Returns the value of attribute failfast.
414 415 416 |
# File 'lib/webspicy/configuration.rb', line 414 def failfast @failfast end |
#file_filter ⇒ Object
Returns the value of attribute file_filter.
252 253 254 |
# File 'lib/webspicy/configuration.rb', line 252 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.
122 123 124 |
# File 'lib/webspicy/configuration.rb', line 122 def folder @folder end |
#generator ⇒ Object
Returns the data generator to use, for generating random data when needed.
474 475 476 |
# File 'lib/webspicy/configuration.rb', line 474 def generator @generator end |
#host ⇒ Object
Returns the value of attribute host.
235 236 237 |
# File 'lib/webspicy/configuration.rb', line 235 def host @host end |
#insecure ⇒ Object
Returns the value of attribute insecure.
425 426 427 |
# File 'lib/webspicy/configuration.rb', line 425 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`.
347 348 349 |
# File 'lib/webspicy/configuration.rb', line 347 def listeners(kind) @listeners[kind] || [] end |
#parent ⇒ Object
Returns the value of attribute parent.
99 100 101 |
# File 'lib/webspicy/configuration.rb', line 99 def parent @parent end |
#postconditions ⇒ Object
Returns the value of attribute postconditions.
152 153 154 |
# File 'lib/webspicy/configuration.rb', line 152 def postconditions @postconditions end |
#preconditions ⇒ Object
Returns the value of attribute preconditions.
145 146 147 |
# File 'lib/webspicy/configuration.rb', line 145 def preconditions @preconditions end |
#reporter ⇒ Object
Returns the value of attribute reporter.
452 453 454 |
# File 'lib/webspicy/configuration.rb', line 452 def reporter @reporter end |
#rspec_options ⇒ Object
Returns the value of attribute rspec_options.
402 403 404 |
# File 'lib/webspicy/configuration.rb', line 402 def @rspec_options end |
#run_counterexamples ⇒ Object
Returns the value of attribute run_counterexamples.
188 189 190 |
# File 'lib/webspicy/configuration.rb', line 188 def run_counterexamples @run_counterexamples end |
#run_examples ⇒ Object
Returns the value of attribute run_examples.
171 172 173 |
# File 'lib/webspicy/configuration.rb', line 171 def run_examples @run_examples end |
#run_generated_counterexamples ⇒ Object
Returns the value of attribute run_generated_counterexamples.
205 206 207 |
# File 'lib/webspicy/configuration.rb', line 205 def run_generated_counterexamples @run_generated_counterexamples end |
#scope_factory ⇒ Object
Returns the value of attribute scope_factory.
114 115 116 |
# File 'lib/webspicy/configuration.rb', line 114 def scope_factory @scope_factory end |
#service_filter ⇒ Object
Returns the value of attribute service_filter.
280 281 282 |
# File 'lib/webspicy/configuration.rb', line 280 def service_filter @service_filter end |
#test_case_filter ⇒ Object
Returns the value of attribute test_case_filter.
304 305 306 |
# File 'lib/webspicy/configuration.rb', line 304 def test_case_filter @test_case_filter end |
#world ⇒ Object (readonly)
Returns the value of attribute world.
56 57 58 |
# File 'lib/webspicy/configuration.rb', line 56 def world @world end |
Class Method Details
.dress(arg, &bl) ⇒ Object
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 88 89 90 91 92 93 |
# File 'lib/webspicy/configuration.rb', line 58 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
95 96 97 |
# File 'lib/webspicy/configuration.rb', line 95 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`.
370 371 372 |
# File 'lib/webspicy/configuration.rb', line 370 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`.
377 378 379 |
# File 'lib/webspicy/configuration.rb', line 377 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`.
384 385 386 |
# File 'lib/webspicy/configuration.rb', line 384 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`.
356 357 358 |
# File 'lib/webspicy/configuration.rb', line 356 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`.
363 364 365 |
# File 'lib/webspicy/configuration.rb', line 363 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.
461 462 463 464 465 466 467 468 469 470 |
# File 'lib/webspicy/configuration.rb', line 461 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
411 412 413 |
# File 'lib/webspicy/configuration.rb', line 411 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
422 423 424 |
# File 'lib/webspicy/configuration.rb', line 422 def default_insecure ENV['INSECURE'] == 'yes' || ENV['INSECURE'] == "1" end |
#default_reporter ⇒ Object
Returns the default reporter to use.
445 446 447 448 449 450 451 |
# File 'lib/webspicy/configuration.rb', line 445 def default_reporter @reporter = Tester::Reporter::Composite.new @reporter << Tester::Reporter::Documentation.new @reporter << Tester::Reporter::Exceptions.new @reporter << Tester::Reporter::Summary.new @reporter << Tester::Reporter::SuccessOrNot.new 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.
311 312 313 314 315 316 317 318 319 320 |
# File 'lib/webspicy/configuration.rb', line 311 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.
485 486 487 488 489 490 491 492 493 494 495 496 497 |
# File 'lib/webspicy/configuration.rb', line 485 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
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/webspicy/configuration.rb', line 102 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
156 157 158 |
# File 'lib/webspicy/configuration.rb', line 156 def errcondition(clazz) errconditions << clazz end |
#factor_scope ⇒ Object
116 117 118 |
# File 'lib/webspicy/configuration.rb', line 116 def factor_scope @scope_factory.call(self) end |
#has_children? ⇒ Boolean
Returns whether this configuration has children configurations or not
163 164 165 |
# File 'lib/webspicy/configuration.rb', line 163 def has_children? !children.empty? end |
#instrument(&instrumentor) ⇒ Object
Installs a listener that will be called right after all precondition instrumentations.
390 391 392 |
# File 'lib/webspicy/configuration.rb', line 390 def instrument(&instrumentor) register_listener(:instrument, instrumentor) end |
#postcondition(clazz) ⇒ Object
Registers a postcondition matcher
149 150 151 |
# File 'lib/webspicy/configuration.rb', line 149 def postcondition(clazz) postconditions << clazz end |
#precondition(clazz) ⇒ Object
Registers a precondition matcher
142 143 144 |
# File 'lib/webspicy/configuration.rb', line 142 def precondition(clazz) preconditions << clazz end |
#run_counterexamples? ⇒ Boolean
Whether counter examples must be ran or not.
191 192 193 |
# File 'lib/webspicy/configuration.rb', line 191 def run_counterexamples? @run_counterexamples end |
#run_examples? ⇒ Boolean
Whether counter examples must be ran or not.
174 175 176 |
# File 'lib/webspicy/configuration.rb', line 174 def run_examples? @run_examples end |
#run_generated_counterexamples? ⇒ Boolean
Whether generated counter examples must be ran or not.
208 209 210 |
# File 'lib/webspicy/configuration.rb', line 208 def run_generated_counterexamples? @run_generated_counterexamples end |