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.
-
#watch_list ⇒ Object
Returns the value of attribute watch_list.
-
#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.
- #default_watchlist ⇒ Object
-
#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 50 |
# 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 @watch_list = default_watchlist 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.
139 140 141 |
# File 'lib/webspicy/configuration.rb', line 139 def children @children end |
#client ⇒ Object
Returns the value of attribute client.
335 336 337 |
# File 'lib/webspicy/configuration.rb', line 335 def client @client end |
#colorize ⇒ Object
Returns the value of attribute colorize.
55 56 57 |
# File 'lib/webspicy/configuration.rb', line 55 def colorize @colorize end |
#colors ⇒ Object
Returns the value of attribute colors.
54 55 56 |
# File 'lib/webspicy/configuration.rb', line 54 def colors @colors end |
#errconditions ⇒ Object
Returns the value of attribute errconditions.
160 161 162 |
# File 'lib/webspicy/configuration.rb', line 160 def errconditions @errconditions end |
#factory ⇒ Object
Returns the value of attribute factory.
114 115 116 |
# File 'lib/webspicy/configuration.rb', line 114 def factory @factory end |
#failfast ⇒ Object
Returns the value of attribute failfast.
415 416 417 |
# File 'lib/webspicy/configuration.rb', line 415 def failfast @failfast end |
#file_filter ⇒ Object
Returns the value of attribute file_filter.
253 254 255 |
# File 'lib/webspicy/configuration.rb', line 253 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.
123 124 125 |
# File 'lib/webspicy/configuration.rb', line 123 def folder @folder end |
#generator ⇒ Object
Returns the data generator to use, for generating random data when needed.
482 483 484 |
# File 'lib/webspicy/configuration.rb', line 482 def generator @generator end |
#host ⇒ Object
Returns the value of attribute host.
236 237 238 |
# File 'lib/webspicy/configuration.rb', line 236 def host @host end |
#insecure ⇒ Object
Returns the value of attribute insecure.
426 427 428 |
# File 'lib/webspicy/configuration.rb', line 426 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`.
348 349 350 |
# File 'lib/webspicy/configuration.rb', line 348 def listeners(kind) @listeners[kind] || [] end |
#parent ⇒ Object
Returns the value of attribute parent.
100 101 102 |
# File 'lib/webspicy/configuration.rb', line 100 def parent @parent end |
#postconditions ⇒ Object
Returns the value of attribute postconditions.
153 154 155 |
# File 'lib/webspicy/configuration.rb', line 153 def postconditions @postconditions end |
#preconditions ⇒ Object
Returns the value of attribute preconditions.
146 147 148 |
# File 'lib/webspicy/configuration.rb', line 146 def preconditions @preconditions end |
#reporter ⇒ Object
Returns the value of attribute reporter.
453 454 455 |
# File 'lib/webspicy/configuration.rb', line 453 def reporter @reporter end |
#rspec_options ⇒ Object
Returns the value of attribute rspec_options.
403 404 405 |
# File 'lib/webspicy/configuration.rb', line 403 def @rspec_options end |
#run_counterexamples ⇒ Object
Returns the value of attribute run_counterexamples.
189 190 191 |
# File 'lib/webspicy/configuration.rb', line 189 def run_counterexamples @run_counterexamples end |
#run_examples ⇒ Object
Returns the value of attribute run_examples.
172 173 174 |
# File 'lib/webspicy/configuration.rb', line 172 def run_examples @run_examples end |
#run_generated_counterexamples ⇒ Object
Returns the value of attribute run_generated_counterexamples.
206 207 208 |
# File 'lib/webspicy/configuration.rb', line 206 def run_generated_counterexamples @run_generated_counterexamples end |
#scope_factory ⇒ Object
Returns the value of attribute scope_factory.
115 116 117 |
# File 'lib/webspicy/configuration.rb', line 115 def scope_factory @scope_factory end |
#service_filter ⇒ Object
Returns the value of attribute service_filter.
281 282 283 |
# File 'lib/webspicy/configuration.rb', line 281 def service_filter @service_filter end |
#test_case_filter ⇒ Object
Returns the value of attribute test_case_filter.
305 306 307 |
# File 'lib/webspicy/configuration.rb', line 305 def test_case_filter @test_case_filter end |
#watch_list ⇒ Object
Returns the value of attribute watch_list.
460 461 462 |
# File 'lib/webspicy/configuration.rb', line 460 def watch_list @watch_list end |
#world ⇒ Object (readonly)
Returns the value of attribute world.
57 58 59 |
# File 'lib/webspicy/configuration.rb', line 57 def world @world end |
Class Method Details
.dress(arg, &bl) ⇒ Object
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 94 |
# File 'lib/webspicy/configuration.rb', line 59 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
96 97 98 |
# File 'lib/webspicy/configuration.rb', line 96 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`.
371 372 373 |
# File 'lib/webspicy/configuration.rb', line 371 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`.
378 379 380 |
# File 'lib/webspicy/configuration.rb', line 378 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`.
385 386 387 |
# File 'lib/webspicy/configuration.rb', line 385 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`.
357 358 359 |
# File 'lib/webspicy/configuration.rb', line 357 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`.
364 365 366 |
# File 'lib/webspicy/configuration.rb', line 364 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.
469 470 471 472 473 474 475 476 477 478 |
# File 'lib/webspicy/configuration.rb', line 469 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
412 413 414 |
# File 'lib/webspicy/configuration.rb', line 412 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
423 424 425 |
# File 'lib/webspicy/configuration.rb', line 423 def default_insecure ENV['INSECURE'] == 'yes' || ENV['INSECURE'] == "1" end |
#default_reporter ⇒ Object
Returns the default reporter to use.
446 447 448 449 450 451 452 |
# File 'lib/webspicy/configuration.rb', line 446 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.
312 313 314 315 316 317 318 319 320 321 |
# File 'lib/webspicy/configuration.rb', line 312 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 |
#default_watchlist ⇒ Object
455 456 457 458 459 |
# File 'lib/webspicy/configuration.rb', line 455 def default_watchlist return nil unless list = ENV['WATCH'] list.split(',').map{|x| Path.pwd/x } 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.
493 494 495 496 497 498 499 500 501 502 503 504 505 |
# File 'lib/webspicy/configuration.rb', line 493 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
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/webspicy/configuration.rb', line 103 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
157 158 159 |
# File 'lib/webspicy/configuration.rb', line 157 def errcondition(clazz) errconditions << clazz end |
#factor_scope ⇒ Object
117 118 119 |
# File 'lib/webspicy/configuration.rb', line 117 def factor_scope @scope_factory.call(self) end |
#has_children? ⇒ Boolean
Returns whether this configuration has children configurations or not
164 165 166 |
# File 'lib/webspicy/configuration.rb', line 164 def has_children? !children.empty? end |
#instrument(&instrumentor) ⇒ Object
Installs a listener that will be called right after all precondition instrumentations.
391 392 393 |
# File 'lib/webspicy/configuration.rb', line 391 def instrument(&instrumentor) register_listener(:instrument, instrumentor) end |
#postcondition(clazz) ⇒ Object
Registers a postcondition matcher
150 151 152 |
# File 'lib/webspicy/configuration.rb', line 150 def postcondition(clazz) postconditions << clazz end |
#precondition(clazz) ⇒ Object
Registers a precondition matcher
143 144 145 |
# File 'lib/webspicy/configuration.rb', line 143 def precondition(clazz) preconditions << clazz end |
#run_counterexamples? ⇒ Boolean
Whether counter examples must be ran or not.
192 193 194 |
# File 'lib/webspicy/configuration.rb', line 192 def run_counterexamples? @run_counterexamples end |
#run_examples? ⇒ Boolean
Whether counter examples must be ran or not.
175 176 177 |
# File 'lib/webspicy/configuration.rb', line 175 def run_examples? @run_examples end |
#run_generated_counterexamples? ⇒ Boolean
Whether generated counter examples must be ran or not.
209 210 211 |
# File 'lib/webspicy/configuration.rb', line 209 def run_generated_counterexamples? @run_generated_counterexamples end |