Class: Fix::On Private

Inherits:
Object
  • Object
show all
Defined in:
lib/fix/on.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Wraps the target of challenge.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(described, results, challenges, helpers, configuration) ⇒ On

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize the on class.



17
18
19
20
21
22
23
# File 'lib/fix/on.rb', line 17

def initialize(described, results, challenges, helpers, configuration)
  @described      = described
  @results        = results
  @challenges     = challenges
  @helpers        = helpers
  @configuration  = configuration
end

Instance Attribute Details

#challengesArray (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The list of challenges to apply.



38
39
40
# File 'lib/fix/on.rb', line 38

def challenges
  @challenges
end

#configurationHash (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Settings.



48
49
50
# File 'lib/fix/on.rb', line 48

def configuration
  @configuration
end

#described#object_id (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The front object of the test.



28
29
30
# File 'lib/fix/on.rb', line 28

def described
  @described
end

#helpersHash (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The list of helpers.



43
44
45
# File 'lib/fix/on.rb', line 43

def helpers
  @helpers
end

#resultsArray (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The list of collected results.



33
34
35
# File 'lib/fix/on.rb', line 33

def results
  @results
end

Instance Method Details

#context(&block) ⇒ Array

Add context method to the DSL, to build an isolated scope.

Examples:

Context when logged in.

context 'when logged in' do
  it { MUST equal 200 }
end


108
109
110
111
112
113
114
115
116
# File 'lib/fix/on.rb', line 108

def context(*, &block)
  o = On.new(described,
             [],
             challenges,
             helpers.dup,
             configuration)

  results.concat Aw.fork! { o.instance_eval(&block) }
end

#it(&spec) ⇒ Array

Add it method to the DSL.

Examples:

It must eql “FOO”

it { MUST equal 'FOO' }


60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fix/on.rb', line 60

def it(*, &spec)
  i = It.new(described, challenges, helpers.dup)

  result = i.verify(&spec)

  if configuration.fetch(:verbose, true)
    print result.to_char(configuration.fetch(:color, false))
  end

  results << result
end

#on(method_name, *args, &block) ⇒ Array

Add on method to the DSL.

Examples:

On +2, it must equal 44.

on(:+, 2) do
  it { MUST equal 44 }
end


86
87
88
89
90
91
92
93
94
# File 'lib/fix/on.rb', line 86

def on(method_name, *args, &block)
  o = On.new(described,
             results,
             (challenges + [Defi.send(method_name, *args)]),
             helpers.dup,
             configuration)

  o.instance_eval(&block)
end