Skip to content

Commit

Permalink
use webrat matchers in generated view specs
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Feb 20, 2010
1 parent ed76f80 commit aa91871
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
8 changes: 4 additions & 4 deletions lib/generators/rspec/scaffold/templates/edit_spec.rb
Expand Up @@ -5,20 +5,20 @@
include <%= controller_class_name %>Helper
before(:each) do
assigns[:<%= file_name %>] = @<%= file_name %> = stub_model(<%= class_name %>,
assign(:<%= file_name %>, @<%= file_name %> = stub_model(<%= class_name %>,
:new_record? => false<%= output_attributes.empty? ? '' : ',' %>
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
<% end -%>
)
))
end
it "renders the edit <%= file_name %> form" do
render
response.should have_tag("form[action=#{<%= file_name %>_path(@<%= file_name %>)}][method=post]") do
response.should have_selector("form", :action => <%= file_name %>_path(@<%= file_name %>), :method => "post") do |form|
<% for attribute in output_attributes -%>
with_tag('<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]', "<%= file_name %>[<%= attribute.name %>]")
form.should have_selector("<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>", :name => "<%= file_name %>[<%= attribute.name %>]")
<% end -%>
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/generators/rspec/scaffold/templates/index_spec.rb
Expand Up @@ -5,7 +5,7 @@
include <%= controller_class_name %>Helper
before(:each) do
assigns[:<%= table_name %>] = [
assign(:<%= table_name %>, [
<% [1,2].each_with_index do |id, model_index| -%>
stub_model(<%= class_name %><%= output_attributes.empty? ? (model_index == 1 ? ')' : '),') : ',' %>
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
Expand All @@ -15,13 +15,13 @@
<%= model_index == 1 ? ')' : '),' %>
<% end -%>
<% end -%>
]
])
end
it "renders a list of <%= table_name %>" do
render
<% for attribute in output_attributes -%>
response.should have_tag("tr>td", <%= attribute.default.inspect %>.to_s, 2)
response.should have_selector("tr>td", :content => <%= attribute.default.inspect %>.to_s, :count => 2)
<% end -%>
end
end
8 changes: 4 additions & 4 deletions lib/generators/rspec/scaffold/templates/new_spec.rb
Expand Up @@ -5,20 +5,20 @@
include <%= controller_class_name %>Helper
before(:each) do
assigns[:<%= file_name %>] = stub_model(<%= class_name %>,
assign(:<%= file_name %>, stub_model(<%= class_name %>,
:new_record? => true<%= output_attributes.empty? ? '' : ',' %>
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
<% end -%>
)
))
end
it "renders new <%= file_name %> form" do
render
response.should have_tag("form[action=?][method=post]", <%= table_name %>_path) do
response.should have_selector("form", :action => "<%= table_name %>_path", :method => "post") do |form|
<% for attribute in output_attributes -%>
with_tag("<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]", "<%= file_name %>[<%= attribute.name %>]")
form.should have_selector("<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>", :name => "<%= file_name %>[<%= attribute.name %>]")
<% end -%>
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/generators/rspec/scaffold/templates/show_spec.rb
Expand Up @@ -4,19 +4,19 @@
describe "/<%= table_name %>/show.html.<%= options[:template_engine] %>" do
include <%= controller_class_name %>Helper
before(:each) do
assigns[:<%= file_name %>] = @<%= file_name %> = stub_model(<%= class_name %><%= output_attributes.empty? ? ')' : ',' %>
assign(:<%= file_name %>, @<%= file_name %> = stub_model(<%= class_name %><%= output_attributes.empty? ? ')' : ',' %>
<% output_attributes.each_with_index do |attribute, attribute_index| -%>
:<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
<% end -%>
<% if !output_attributes.empty? -%>
)
))
<% end -%>
end
it "renders attributes in <p>" do
render
<% for attribute in output_attributes -%>
response.should have_text(/<%= Regexp.escape(attribute.default.inspect).gsub(/^"|"$/, '')%>/)
response.should contain(<%= attribute.default.inspect %>)
<% end -%>
end
end
1 change: 1 addition & 0 deletions lib/rspec/rails/example.rb
@@ -1,2 +1,3 @@
require 'rspec/rails/example/controller_example_group'
require 'rspec/rails/example/request_example_group'
require 'rspec/rails/example/view_example_group'

0 comments on commit aa91871

Please sign in to comment.