Class: Spec::Rails::Matchers::AssertSelect

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/rails/matchers/assert_select.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(assertion, spec_scope, *args, &block) ⇒ AssertSelect

Returns a new instance of AssertSelect.



9
10
11
12
13
14
# File 'lib/spec/rails/matchers/assert_select.rb', line 9

def initialize(assertion, spec_scope, *args, &block)
  @assertion = assertion
  @spec_scope = spec_scope
  @args = args
  @block = block
end

Instance Method Details

#descriptionObject



37
38
39
40
41
42
# File 'lib/spec/rails/matchers/assert_select.rb', line 37

def description
  {
    :assert_select => "have tag#{format_args(*@args)}",
    :assert_select_email => "send email#{format_args(*@args)}",
  }[@assertion]
end

#failure_messageObject



34
# File 'lib/spec/rails/matchers/assert_select.rb', line 34

def failure_message; @error.message; end

#matches?(response_or_text, &block) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/spec/rails/matchers/assert_select.rb', line 16

def matches?(response_or_text, &block)
  if ActionController::TestResponse === response_or_text and
           response_or_text.headers.key?('Content-Type') and
           !response_or_text.headers['Content-Type'].blank? and
           response_or_text.headers['Content-Type'].to_sym == :xml
    @args.unshift(HTML::Document.new(response_or_text.body, false, true).root)           
  elsif String === response_or_text
    @args.unshift(HTML::Document.new(response_or_text).root)
  end
  @block = block if block
  begin
    @spec_scope.__send__(@assertion, *@args, &@block)
  rescue ::Test::Unit::AssertionFailedError => @error
  end
  
  @error.nil?
end

#negative_failure_messageObject



35
# File 'lib/spec/rails/matchers/assert_select.rb', line 35

def negative_failure_message; "should not #{description}, but did"; end