Created
June 8, 2011 18:06
-
-
Save citrus/1014960 to your computer and use it in GitHub Desktop.
Capybara Integration Case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActiveSupport::IntegrationCase < ActiveSupport::TestCase | |
include Capybara | |
include Rails.application.routes.url_helpers | |
self.use_transactional_fixtures = false | |
# Checks for missing translations after each test | |
teardown do | |
unless source.blank? | |
matches = source.match(/translation[\s-]+missing[^"]*/) || [] | |
assert_equal 0, matches.length, "Translation Missing! - #{matches[0]}" | |
end | |
end | |
# An assertion for ensuring content has made it to the page. | |
# | |
# assert_seen "Site Title" | |
# assert_seen "Peanut Butter Jelly Time", :within => ".post-title h1" | |
# | |
def assert_seen(text, opts={}) | |
if opts[:within] | |
within(opts[:within]) do | |
assert has_content?(text) | |
end | |
else | |
assert has_content?(text) | |
end | |
end | |
# Asserts the proper flash message | |
# | |
# assert_flash :notice, "Post was successfully saved!" | |
# assert_flash :error, "Oh No, bad things happened!" | |
# | |
def assert_flash(key, text) | |
within(".flash.#{key}") do | |
assert_seen(text) | |
end | |
end | |
# Asserts the proper browser title | |
# | |
# assert_title "My Site - Is super cool" | |
# | |
def assert_title(title) | |
assert_seen title, :within => "head title" | |
end | |
# Asserts meta tags have proper content | |
# | |
# assert_meta :description, "So let me tell you about this one time..." | |
# assert_meta :keywords, "seo, is, fun, jk." | |
# | |
def assert_meta(tag, text) | |
tag = find(:xpath, "//head/meta[@name='#{tag.to_s}']") | |
assert_equal text, tag.native.attribute("content") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment