2016-11-17 1 views
0

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 
01 23,516,

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.

... 단지 <tag>String</tag>에 대한

+0

''1.to_s' => ' "에 대한 같은 단지'"을 MyString을 "'쓰기, 이해가되지 않습니다 .to_s'"MyString에 "1 " ' –

답변

1

assert_select "tag", "String" 일치. 일치하는 부분을 원하면 <tag>a String</tag>과 일치하는 Regex assert_select "tag", /String/을 사용할 수 있습니다. 귀하의 경우에는

이 작동합니다 :

assert_select "tr>td", :text => /MyString/, :count => 2 
+0

고맙습니다. 설명 : –

관련 문제