From 2121ff12fb58ed2f8e4fff095a7ac9555da02f9e Mon Sep 17 00:00:00 2001 From: Jonathan del Strother Date: Tue, 31 Dec 2013 10:55:35 +0000 Subject: [PATCH] Update HaveText & HaveTitle to silence deprecations on RSpec3 --- lib/capybara/rspec/matchers.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/capybara/rspec/matchers.rb b/lib/capybara/rspec/matchers.rb index b6529cfb..64a42f8b 100644 --- a/lib/capybara/rspec/matchers.rb +++ b/lib/capybara/rspec/matchers.rb @@ -51,16 +51,20 @@ module Capybara @actual.has_no_text?(type, content, options) end - def failure_message_for_should + def failure_message message = Capybara::Helpers.failure_message(description, options) message << " in #{format(@actual.text(type))}" message end - def failure_message_for_should_not - failure_message_for_should.sub(/(to find)/, 'not \1') + def failure_message_when_negated + failure_message.sub(/(to find)/, 'not \1') end + # RSpec 2 compatibility: + alias_method :failure_message_for_should, :failure_message + alias_method :failure_message_for_should_not, :failure_message_when_negated + def description "text #{format(content)}" end @@ -88,14 +92,18 @@ module Capybara @actual.has_no_title?(title) end - def failure_message_for_should + def failure_message "expected there to be title #{title.inspect} in #{@actual.title.inspect}" end - def failure_message_for_should_not + def failure_message_when_negated "expected there not to be title #{title.inspect} in #{@actual.title.inspect}" end + # RSpec 2 compatibility: + alias_method :failure_message_for_should, :failure_message + alias_method :failure_message_for_should_not, :failure_message_when_negated + def description "have title #{title.inspect}" end