Class: Webspicy::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/webspicy/configuration.rb

Constant Summary collapse

LISTENER_KINDS =
[ :before_all, :before_each, :after_all, :after_each, :around_each ]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(folder = Path.pwd, parent = nil) {|_self| ... } ⇒ Configuration

Returns a new instance of Configuration.

Yields:

  • (_self)

Yield Parameters:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/webspicy/configuration.rb', line 6

def initialize(folder = Path.pwd, parent = nil)
  @folder = folder
  @parent = parent
  @children = []
  @preconditions = []
  @postconditions = []
  @listeners = Hash.new{|h,k| h[k] = [] }
  @rspec_options = default_rspec_options
  @run_counterexamples = default_run_counterexamples
  @file_filter = default_file_filter
  @service_filter = default_service_filter
  @client = HttpClient
  Path.require_tree(folder/'support') if (folder/'support').exists?
  yield(self) if block_given?
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



74
75
76
# File 'lib/webspicy/configuration.rb', line 74

def children
  @children
end

#clientObject

Returns the value of attribute client.



197
198
199
# File 'lib/webspicy/configuration.rb', line 197

def client
  @client
end

#file_filterObject

Returns the value of attribute file_filter.



147
148
149
# File 'lib/webspicy/configuration.rb', line 147

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.



58
59
60
# File 'lib/webspicy/configuration.rb', line 58

def folder
  @folder
end

#hostObject

Returns the value of attribute host.



130
131
132
# File 'lib/webspicy/configuration.rb', line 130

def host
  @host
end

#listeners(kind) ⇒ Object

Returns the listeners of a specific kind.

Recognized kinds are ‘before_each`, `after_each`, `before_all`, `after_all` and `instrument`.



210
211
212
# File 'lib/webspicy/configuration.rb', line 210

def listeners(kind)
  @listeners[kind] || []
end

#parentObject

Returns the value of attribute parent.



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

def parent
  @parent
end

#postconditionsObject

Returns the value of attribute postconditions.



88
89
90
# File 'lib/webspicy/configuration.rb', line 88

def postconditions
  @postconditions
end

#preconditionsObject

Returns the value of attribute preconditions.



81
82
83
# File 'lib/webspicy/configuration.rb', line 81

def preconditions
  @preconditions
end

#rspec_optionsObject

Returns the value of attribute rspec_options.



265
266
267
# File 'lib/webspicy/configuration.rb', line 265

def rspec_options
  @rspec_options
end

#run_counterexamplesObject

Returns the value of attribute run_counterexamples.



100
101
102
# File 'lib/webspicy/configuration.rb', line 100

def run_counterexamples
  @run_counterexamples
end

#service_filterObject

Returns the value of attribute service_filter.



172
173
174
# File 'lib/webspicy/configuration.rb', line 172

def service_filter
  @service_filter
end

Class Method Details

.dress(arg, &bl) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/webspicy/configuration.rb', line 24

def self.dress(arg, &bl)
  return arg if arg.is_a?(Configuration)
  arg = Path(arg)
  if arg.file?
    c = Kernel.instance_eval arg.read, arg.to_s
    yield(c) if block_given?
    c
  elsif (arg/'config.rb').file?
    dress(arg/'config.rb', &bl)
  else
    raise ArgumentError, "Missing config.rb file"
  end
end

.inherits(*args, &bl) ⇒ Object



38
39
40
# File 'lib/webspicy/configuration.rb', line 38

def self.inherits(*args, &bl)
  dress(*args, &bl)
end

Instance Method Details

#after_all(&listener) ⇒ Object

Installs a listener that will be called after all tests

The ‘listener` must respond to `call`.



233
234
235
# File 'lib/webspicy/configuration.rb', line 233

def after_all(&listener)
  register_listener(:after_all, listener)
end

#after_each(&listener) ⇒ Object

Installs a listener that will be called after each web service invocation.

The ‘listener` must respond to `call`.



240
241
242
# File 'lib/webspicy/configuration.rb', line 240

def after_each(&listener)
  register_listener(:after_each, listener)
end

#around_each(&listener) ⇒ Object

Installs a listener that will be called around each web service invocation.

The ‘listener` must respond to `call`.



247
248
249
# File 'lib/webspicy/configuration.rb', line 247

def around_each(&listener)
  register_listener(:around_each, listener)
end

#before_all(&listener) ⇒ Object

Installs a listener that will be called before all tests

The ‘listener` must respond to `call`.



219
220
221
# File 'lib/webspicy/configuration.rb', line 219

def before_all(&listener)
  register_listener(:before_all, listener)
end

#before_each(&listener) ⇒ Object

Installs a listener that will be called before each web service invocation.

The ‘listener` must respond to `call`.



226
227
228
# File 'lib/webspicy/configuration.rb', line 226

def before_each(&listener)
  register_listener(:before_each, listener)
end

#data_systemObject

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.



291
292
293
294
295
296
297
298
299
300
# File 'lib/webspicy/configuration.rb', line 291

def data_system
  schema = self.folder/"schema.fio"
  if schema.file?
    Finitio::DEFAULT_SYSTEM.parse(schema.read)
  elsif not(self.parent.nil?)
    self.parent.data_system
  else
    Finitio::DEFAULT_SYSTEM
  end
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.



308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/webspicy/configuration.rb', line 308

def dup(&bl)
  super.tap do |d|
    d.children = []
    d.preconditions = self.preconditions.dup
    d.postconditions = self.postconditions.dup
    d.rspec_options = self.rspec_options.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



45
46
47
48
49
50
51
52
53
54
# File 'lib/webspicy/configuration.rb', line 45

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 Scope.new(self)
  end
end

#has_children?Boolean

Returns whether this configuration has children configurations or not

Returns:

  • (Boolean)


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

def has_children?
  !children.empty?
end

#instrument(&instrumentor) ⇒ Object

Installs a listener that will be called right after all precondition instrumentations.



253
254
255
# File 'lib/webspicy/configuration.rb', line 253

def instrument(&instrumentor)
  register_listener(:instrument, instrumentor)
end

#postcondition(clazz) ⇒ Object

Registers a postcondition matcher



85
86
87
# File 'lib/webspicy/configuration.rb', line 85

def postcondition(clazz)
  postconditions << clazz
end

#precondition(clazz) ⇒ Object

Registers a precondition matcher



78
79
80
# File 'lib/webspicy/configuration.rb', line 78

def precondition(clazz)
  preconditions << clazz
end

#run_counterexamples?Boolean

Whether counter examples must be ran or not.

Returns:

  • (Boolean)


103
104
105
# File 'lib/webspicy/configuration.rb', line 103

def run_counterexamples?
  @run_counterexamples
end