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(front_object, 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.

Parameters:

  • front_object (#object_id)

    The front object of the test.

  • results (Array)

    The list of collected results.

  • challenges (Array)

    The list of challenges to apply.

  • helpers (Hash)

    The list of helpers.

  • configuration (Hash)

    Settings.



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

def initialize(front_object, results, challenges, helpers, configuration)
  @front_object   = front_object
  @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.

Returns:

  • (Array)

    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.

Returns:

  • (Hash)

    Settings.



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

def configuration
  @configuration
end

#front_object#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.

Returns:

  • (#object_id)

    The front object of the test.



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

def front_object
  @front_object
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.

Returns:

  • (Hash)

    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.

Returns:

  • (Array)

    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

Parameters:

  • block (Proc)

    A block of specs to test in isolation.

Returns:

  • (Array)

    List of results.



112
113
114
115
116
117
118
119
120
# File 'lib/fix/on.rb', line 112

def context(*, &block)
  o = On.new(front_object,
             results,
             challenges,
             helpers.dup,
             configuration)

  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' }

Parameters:

  • spec (Proc)

    A spec to compare against the computed actual value.

Returns:

  • (Array)

    List of results.



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

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

  result = begin
             i.instance_eval(&spec)
           rescue Spectus::Result::Fail => f
             f
           end

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

  results << result
end

#let(method_name, &block) ⇒ #object_id

Returns List of results.

Examples:

Let’s define the answer to the Ultimate Question of Life, the

Universe, and Everything.

let(:answer) { 42 }

Parameters:

  • method_name (Symbol)

    The identifier of a method.

  • block (Proc)

    A spec to compare against the computed value.

Returns:

  • (#object_id)

    List of results.



133
134
135
# File 'lib/fix/on.rb', line 133

def let(method_name, &block)
  helpers.update(method_name => block)
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

Parameters:

  • method_name (Symbol)

    The identifier of a method.

  • args (Array)

    A list of arguments.

  • block (Proc)

    A spec to compare against the computed value.

Returns:

  • (Array)

    List of results.



90
91
92
93
94
95
96
97
98
# File 'lib/fix/on.rb', line 90

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

  o.instance_eval(&block)
end