Class: Capybara::RSpecMatchers::HaveMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/rspec/matchers.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (HaveMatcher) initialize(name, locator, options = {}, &block)



56
57
58
59
60
61
# File 'lib/capybara/rspec/matchers.rb', line 56

def initialize(name, locator, options={}, &block)
  @name = name
  @locator = locator
  @options = options
  @failure_message = block
end

Instance Attribute Details

- (Object) actual (readonly)

Returns the value of attribute actual



54
55
56
# File 'lib/capybara/rspec/matchers.rb', line 54

def actual
  @actual
end

- (Object) failure_message (readonly)

Returns the value of attribute failure_message



54
55
56
# File 'lib/capybara/rspec/matchers.rb', line 54

def failure_message
  @failure_message
end

- (Object) locator (readonly)

Returns the value of attribute locator



54
55
56
# File 'lib/capybara/rspec/matchers.rb', line 54

def locator
  @locator
end

- (Object) name (readonly)

Returns the value of attribute name



54
55
56
# File 'lib/capybara/rspec/matchers.rb', line 54

def name
  @name
end

- (Object) options (readonly)

Returns the value of attribute options



54
55
56
# File 'lib/capybara/rspec/matchers.rb', line 54

def options
  @options
end

Instance Method Details

- (Object) arguments



63
64
65
# File 'lib/capybara/rspec/matchers.rb', line 63

def arguments
  if options.empty? then [locator] else [locator, options] end
end

- (Object) description



89
90
91
# File 'lib/capybara/rspec/matchers.rb', line 89

def description
  "has #{selector_name}"
end

- (Boolean) does_not_match?(actual)



72
73
74
75
# File 'lib/capybara/rspec/matchers.rb', line 72

def does_not_match?(actual)
  @actual = wrap(actual)
  @actual.send(:has_no_#{name}?", *arguments)
end

- (Object) failure_message_for_should



77
78
79
80
81
82
83
# File 'lib/capybara/rspec/matchers.rb', line 77

def failure_message_for_should
  if failure_message
    failure_message.call(actual, self)
  else
    "expected #{selector_name} to return something"
  end
end

- (Object) failure_message_for_should_not



85
86
87
# File 'lib/capybara/rspec/matchers.rb', line 85

def failure_message_for_should_not
  "expected #{selector_name} not to return anything"
end

- (Boolean) matches?(actual)



67
68
69
70
# File 'lib/capybara/rspec/matchers.rb', line 67

def matches?(actual)
  @actual = wrap(actual)
  @actual.send(:has_#{name}?", *arguments)
end

- (Object) selector_name



93
94
95
96
97
# File 'lib/capybara/rspec/matchers.rb', line 93

def selector_name
  selector_name = "#{name} #{locator.inspect}"
  selector_name << " with text #{options[:text].inspect}" if options[:text]
  selector_name
end

- (Object) wrap(actual)



99
100
101
102
103
104
105
# File 'lib/capybara/rspec/matchers.rb', line 99

def wrap(actual)
  if actual.respond_to?("has_selector?")
    actual
  else
    Capybara.string(actual.to_s)
  end
end