Skip to content

Instantly share code, notes, and snippets.

@kyamaguchi
Created May 22, 2012 02:41
Show Gist options
  • Save kyamaguchi/2766210 to your computer and use it in GitHub Desktop.
Save kyamaguchi/2766210 to your computer and use it in GitHub Desktop.
RSpec TranslationMissingDetector
# spec/support/detect_translation_missing.rb
module TranslationMissingDetector
module Capybara::Node::Finders
alias_method :find_original, :find
def find(*args)
begin
m = session.body.match(/translation[_ ]missing[^<]+/)
puts ["="*80, m[0], '', caller].join("\n")+"\n\n" if m
m = session.body.match(/>ja, [^<]+/)
puts ["="*80, m[0], '', caller].join("\n")+"\n\n" if m
find_original(*args)
rescue => e
session.save_and_open_page if session.respond_to?(:save_and_open_page)
raise e
end
end
end
end
::Capybara::Node::Finders.send :include, TranslationMissingDetector
module HaveMatcherExtension
module Capybara::RSpecMatchers
alias_method :have_content_original, :have_content
def have_content(text)
# debugger
m = page.body.match(/translation/)
puts ["="*80, m[0], '', caller].join("\n")+"\n\n" if m
m = page.body.match(/ja, \w+/)
puts ["="*80, m[0], '', caller].join("\n")+"\n\n" if m
m = page.body.match(/translation[_ ]missing[^<]+/)
puts ["="*80, m[0], '', caller].join("\n")+"\n\n" if m
m = page.body.match(/>ja, [^<]+/)
puts ["="*80, m[0], '', caller].join("\n")+"\n\n" if m
HaveMatcher.new(:content, text.to_s) do |page, matcher|
%(expected there to be content #{matcher.locator.inspect} in #{page.text.inspect})
end
end
end
end
::Capybara::RSpecMatchers.send :include, HaveMatcherExtension
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment