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.

Parameters:

  • described (#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.


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

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.

Returns:

  • (Array)

    The list of challenges to apply.


40
41
42
# File 'lib/fix/on.rb', line 40

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.


50
51
52
# File 'lib/fix/on.rb', line 50

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.

Returns:

  • (#object_id)

    The front object of the test.


30
31
32
# File 'lib/fix/on.rb', line 30

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.

Returns:

  • (Hash)

    The list of helpers.


45
46
47
# File 'lib/fix/on.rb', line 45

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.


35
36
37
# File 'lib/fix/on.rb', line 35

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.


127
128
129
130
131
132
133
134
135
# File 'lib/fix/on.rb', line 127

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

Parameters:

  • spec (Proc)

    A spec to compare against the computed actual value.

Returns:

  • (Array)

    List of results.


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

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

  result = i.verify(&spec)

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

  results << result
end

#let(method_name, &block) ⇒ #object_id

Add let method to the DSL, to define memoized helper methods.

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.


111
112
113
# File 'lib/fix/on.rb', line 111

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.


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

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