Merge branch 'added_title_checking' of git://github.com/thechrisoshow/shoulda into thechrisoshow/added_title_checking
* 'added_title_checking' of git://github.com/thechrisoshow/shoulda: Added new method should_render_page_with_metadata with tests [#61] Conflicts: lib/shoulda/controller/macros.rb
This commit is contained in:
commit
1f535f17d5
|
@ -269,6 +269,28 @@ module Shoulda # :nodoc:
|
|||
end
|
||||
end
|
||||
|
||||
# Macro that creates a test asserting that the rendered view contains the selected metatags.
|
||||
# Values can be string or Regexps.
|
||||
# Example:
|
||||
#
|
||||
# should_render_page_with_metadata :description => "Description of this page", :keywords => /post/
|
||||
#
|
||||
# You can also use this method to test the rendered views title.
|
||||
#
|
||||
# Example:
|
||||
# should_render_page_with_metadata :title => /index/
|
||||
def should_render_page_with_metadata(options)
|
||||
options.each do |key, value|
|
||||
should "have metatag #{key}" do
|
||||
if key.to_sym == :title
|
||||
assert_select "title", value
|
||||
else
|
||||
assert_select "meta[name=?][content#{"*" if value.is_a?(Regexp)}=?]", key, value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Macro that creates a routing test. It tries to use the given HTTP
|
||||
# +method+ on the given +path+, and asserts that it routes to the
|
||||
# given +options+.
|
||||
|
|
|
@ -73,6 +73,8 @@ class PostsControllerTest < Test::Unit::TestCase
|
|||
end
|
||||
should_assign_to :posts
|
||||
should_not_assign_to :foo, :bar
|
||||
should_render_page_with_metadata :description => /Posts/, :title => /index/
|
||||
should_render_page_with_metadata :keywords => "posts"
|
||||
end
|
||||
|
||||
context "viewing posts for a user with rss format" do
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
||||
<meta name="description" content="Posts, posts and more posts" />
|
||||
<meta name='keywords' content='posts' />
|
||||
<title>Posts: <%= controller.action_name %></title>
|
||||
<%= stylesheet_link_tag 'scaffold' %>
|
||||
</head>
|
||||
|
|
Loading…
Reference in New Issue