Class: Test::Unit::Assertions::AssertRjs

Inherits:
Object
  • Object
show all
Defined in:
lib/assert2/rjs.rb

Direct Known Subclasses

ALERT, CALL, REMOVE, REPLACE_HTML

Defined Under Namespace

Classes: ALERT, CALL, REMOVE, REPLACE, REPLACE_HTML

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(js, command, scope) ⇒ AssertRjs

Returns a new instance of AssertRjs.



12
13
14
# File 'lib/assert2/rjs.rb', line 12

def initialize(js, command, scope)
  @js, @command, @scope = js, command, scope
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



16
17
18
# File 'lib/assert2/rjs.rb', line 16

def command
  @command
end

#failure_messageObject (readonly)

Returns the value of attribute failure_message.



16
17
18
# File 'lib/assert2/rjs.rb', line 16

def failure_message
  @failure_message
end

#jsObject (readonly)

Returns the value of attribute js.



16
17
18
# File 'lib/assert2/rjs.rb', line 16

def js
  @js
end

#scopeObject (readonly)

Returns the value of attribute scope.



16
17
18
# File 'lib/assert2/rjs.rb', line 16

def scope
  @scope
end

Instance Method Details

#assert_xhtml(why, &block) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/assert2/rjs.rb', line 51

def assert_xhtml(why, &block)
    #  scope.assert_xhtml @text, complain(why), &block      
  matcher = BeHtmlWith.new(self, &block)
  matcher.message = complain(why)
  matcher.matches?(@text, &block)
  @failure_message = matcher.failure_message
end

#complain(about) ⇒ Object

TODO implement assert_no_rjs by upgrading scope to UnScope



30
31
32
# File 'lib/assert2/rjs.rb', line 30

def complain(about)
  "#{ command } #{ about }\n#{ js }"
end

#flunk(about) ⇒ Object



34
35
36
# File 'lib/assert2/rjs.rb', line 34

def flunk(about)
  @failure_message ||= complain(about)
end

#match(kode) ⇒ Object

TODO rename js to sample



19
20
21
22
23
24
25
26
# File 'lib/assert2/rjs.rb', line 19

def match(kode)
  RKelly.parse(js).pointcut(kode).
      matches.each do |updater|
    updater.grep(RKelly::Nodes::ArgumentsNode).each do |thang|
      yield thang
    end
  end
end

#match_or_flunk(why) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/assert2/rjs.rb', line 38

def match_or_flunk(why)  
  @text = @text.to_s
  @matcher = @matcher.to_s if @matcher.kind_of?(Symbol)
  return if Regexp.new(@matcher) =~ @text or @text.index(@matcher)
  @failure_message = scope.build_message(complain(why),
                              "<?> expected to be =~\n<?>.", @text, @matcher)
end

#pwn_call(*args, &block) ⇒ Object

TODO use or reject the block



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/assert2/rjs.rb', line 59

def pwn_call *args, &block  #  TODO  use or reject the block
  target, matchers_backup = args[0], args[1..-1]
  
  match "#{target}()" do |thang|
    matchers = matchers_backup.dup
    
    thang.value.each do |arg|
      @text = eval(arg.value)
      @matcher = matchers.first # or return @text
      @matcher.to_s == @text or /#{ @matcher }/ =~ @text or break
      matchers.shift
    end
    
    matchers.empty? and 
      matchers_backup.length == thang.value.length and 
      return @text 
  end
  
  matchers = matchers_backup.inspect

  flunk("#{ command } to #{ target } with arguments #{ 
                    matchers } not found in #{ js }")
end

#wrap_expectation(whatever) ⇒ Object

ERGO blog about how bottom-up TDD decouples

ERGO  assert_no_rjs_ ...without! ... oh the humanity!


49
# File 'lib/assert2/rjs.rb', line 49

def wrap_expectation whatever;  yield;  end