Class: Expect

Inherits:
Object
  • Object
show all
Defined in:
lib/pidgin_spec/expect.rb

Defined Under Namespace

Classes: NoMatcherError

Instance Method Summary collapse

Constructor Details

#initialize(value, klass, self_klass, spec_statement, des_statement) ⇒ Expect

Returns a new instance of Expect.



5
6
7
8
9
10
11
# File 'lib/pidgin_spec/expect.rb', line 5

def initialize(value, klass, self_klass, spec_statement, des_statement)
  @klass = klass
  @value = value
  @des_statement = des_statement
  @spec_statement = spec_statement
  @self_klass = self_klass
end

Instance Method Details

#go(matcher) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pidgin_spec/expect.rb', line 13

def go(matcher)
  
  if matcher.matches?(@value)
    @klass.pass_count += 1
  else
    @klass.fail_count += 1
    @klass.failure_messages << {
      description: "#{@des_statement} #{@spec_statement}",
       message: matcher.failure_message,
       failed_code: failed_code(caller_locations[0]),
       failed_code_path: "#{caller_locations[0].path.to_s}:#{caller_locations[0].lineno.to_s}"
      }
    @self_klass.passed = false
  end
end

#no_go(matcher) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pidgin_spec/expect.rb', line 29

def no_go(matcher)
  if !matcher.matches?(@value)
    @klass.pass_count += 1
  else
    @klass.fail_count += 1
    @klass.failure_messages << {
      description: "#{@des_statement} #{@spec_statement}",
       message: matcher.failure_message_when_negated,
       failed_code: failed_code(caller_locations[0]),
       failed_code_path: "#{caller_locations[0].path.to_s}:#{caller_locations[0].lineno.to_s}"
      }
    @self_klass.passed = false
  end
end