Add matcher for javascript error checking

This commit is contained in:
Joe Fiorini 2011-10-31 14:35:51 -04:00
parent 62b49914b8
commit 741261c6d0
1 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,39 @@
module Capybara
module Webkit
module RspecMatchers
extend RSpec::Matchers::DSL
matcher :have_errors do |expected|
match do |actual|
actual = resolve(actual)
actual.error_messages.any?
end
failure_message_for_should do |actual|
"Expected Javascript errors, but there were none."
end
failure_message_for_should_not do |actual|
actual = resolve(actual)
"Expected no Javascript errors, got:\n#{error_messages_for(actual)}"
end
def error_messages_for(obj)
obj.error_messages.map do |m|
" - #{m[:message]}"
end.join("\n")
end
def resolve(actual)
if actual.respond_to? :page
actual.page.driver
elsif actual.respond_to? :driver
actual.driver
else
actual
end
end
end
end
end
end