index.html.erb_spec.rb失敗/エラー:assert_select "TR> TD"、:テキスト=> "のMyString" .to_s、:=> 2
require 'spec_helper'
describe "instructions/index" do
before(:each) do
assign(:instructions, Kaminari.paginate_array([
stub_model(Instruction,
:path => "MyString",
:content => "Content",
:creator_id => 1,
:modifier_id => 2,
:updated_at => "2011-03-15"
),
stub_model(Instruction,
:path => "MyString",
:content => "Content",
:creator_id => 1,
:modifier_id => 2,
:updated_at => "2011-03-15"
)
]).page(1))
end
it "renders a list of instructions" do
render
# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "tr>td", :text => "MyString".to_s, :count => 2
assert_select "tr>td", :text => "Content".to_s, :count => 2
assert_select "tr>td", :text => 1.to_s, :count => 2
assert_select "tr>td", :text => 2.to_s, :count => 2
assert_select "tr>td", :text => "2011-03-15".to_s, :count => 2
end
end
のindex.htmlを数えます。 ERB
<% title "Help Contents" %>
<%= paginate @instructions %>
<table class="table table-striped table-bordered" id="tips">
<thead>
<tr>
<th>Path</th>
<th>Content</th>
<th>Creator</th>
<th>Modifier</th>
<th>Last Modified</th>
<th class="no_sort"><%=t '.actions', :default => t("helpers.actions") %></th>
</tr>
</thead>
<tbody>
<% @instructions.each do |instruction| %>
<tr>
<td>
<%= instruction.actual_path %><br />
<span class="smallesttext">(<%= instruction.path %>)</span>
</td>
<td><%= truncate_html(simple_format(instruction.content), :length => 30) %></td>
<td><%= instruction.creator.reverse_full_name if instruction.creator %></td>
<td><%= instruction.modifier.reverse_full_name if instruction.modifier %></td>
<td><%= l instruction.updated_at, :format => :pretty %></td>
<td>
<%= link_to t('.show', :default => t("helpers.links.show")),
help_path(instruction), :class => 'btn btn-mini btn-info' %>
<%= link_to t('.edit', :default => t("helpers.links.edit")),
edit_help_path(instruction), :class => 'btn btn-mini' %>
<%= link_to t('.destroy', :default => t("helpers.links.destroy")),
help_path(instruction),
:method => :delete,
:confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
:class => 'btn btn-mini btn-danger' %>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= paginate @instructions %>
<%= link_to "New Help Item",
new_help_path,
:class => 'btn btn-primary' %>
instructions_controller.rb
class InstructionsController < ApplicationController
respond_to :html, :xml, :json
layout :single_column_layout
before_filter :admin_only, :except => [:show]
def index
@instructions = Instruction.includes(:creator,:modifier).page(params[:page])
respond_with(@instructions)
end
end
ERROR
Failure/Error: assert_select "tr>td", :text => "MyString".to_s, :count => 2 Test::Unit::AssertionFailedError: <"MyString"> expected but was <"unknown\n\t\t\t\t(MyString)"> false is not true.
のみに対する
'' 1.to_s' => ' "のために同じだけの' "のMyStringを" '書き、意味がありません.to_s' "のMyString"、1 " –