class Fix::On
Wraps the target of challenge.
@api private
Attributes
@!attribute [r] challenges
@return [Array] The list of challenges to apply.
@!attribute [r] configuration
@return [Hash] Settings.
@!attribute [r] described
@return [#object_id] The front object of the test.
@!attribute [r] helpers
@return [Hash] The list of helpers.
@!attribute [r] results
@return [Array] The list of collected results.
Public Class Methods
Initialize the on class.
@param described [#object_id] The front object of the test. @param results [Array] The list of collected results. @param challenges [Array] The list of challenges to apply. @param helpers [Hash] The list of helpers. @param configuration [Hash] Settings.
# 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
Public Instance Methods
Add context method to the DSL, to build an isolated scope.
@api public
@example Context when logged in.
context 'when logged in' do it { MUST equal 200 } end
@param block [Proc] A block of specs to test in isolation.
@return [Array] List of results.
# 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
Add it method to the DSL.
@api public
@example It
must eql “FOO”
it { MUST equal 'FOO' }
@param spec [Proc] A spec to compare against the computed actual value.
@return [Array] List of results.
# 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
Add let method to the DSL, to define memoized helper methods.
@api public
@example Let's define the answer to the Ultimate Question of Life, the
Universe, and Everything. let(:answer) { 42 }
@param method_name [Symbol] The identifier of a method. @param block [Proc] A spec to compare against the computed value.
@return [#object_id] List of results.
# File lib/fix/on.rb, line 111 def let(method_name, &block) helpers.update(method_name => block) end
Add on method to the DSL.
@api public
@example On
+2, it must equal 44.
on(:+, 2) do it { MUST equal 44 } end
@param method_name [Symbol] The identifier of a method. @param args [Array] A list of arguments. @param block [Proc] A spec to compare against the computed value.
@return [Array] List of results.
# 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