Capybara :: ElementNotFound - Rspec

时间:2014-08-14 17:59:33

标签: ruby-on-rails ruby rspec capybara rspec3

这让我发疯了。请帮助,我确定这是一个简单的修复,即使它是一个愚蠢的树屋todo应用程序。 (所以你们午餐时间经验丰富的程序员请帮助我,如果需要,我不会诉诸于此)。

我试图创建一个身份验证系统,但由于无法找到css而导致失败,#todo_list_1"

这是我运行BIN / RAKE

之后的全部内容

这是我失败的清单:

故障:

1) Editing todo items is successful with valid content
 Failure/Error: visit_todo_list(todo_list)
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/support/todo_list_helpers.rb:4:in `visit_todo_list'
 # ./spec/features/todo_items/edit_spec.rb:9:in `block (2 levels) in <top (required)>'

2) Editing todo items is unsuccessful with not enough content
 Failure/Error: visit_todo_list(todo_list)
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/support/todo_list_helpers.rb:4:in `visit_todo_list'
 # ./spec/features/todo_items/edit_spec.rb:34:in `block (2 levels) in <top (required)>'

3) Editing todo items is unsuccessful with no content
 Failure/Error: visit_todo_list(todo_list)
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/support/todo_list_helpers.rb:4:in `visit_todo_list'
 # ./spec/features/todo_items/edit_spec.rb:21:in `block (2 levels) in <top (required)>'

4) Editing todo lists updates a todo list successfully with correct information
 Failure/Error: within "#todo_list_#{todo_list.id}" do
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/features/todo_lists/edit_spec.rb:14:in `update_todo_list'
 # ./spec/features/todo_lists/edit_spec.rb:24:in `block (2 levels) in <top (required)>'

5) Editing todo lists displays an error with too short a title
 Failure/Error: within "#todo_list_#{todo_list.id}" do
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/features/todo_lists/edit_spec.rb:14:in `update_todo_list'
 # ./spec/features/todo_lists/edit_spec.rb:44:in `block (2 levels) in <top (required)>'

6) Editing todo lists displays an error with no title
 Failure/Error: within "#todo_list_#{todo_list.id}" do
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/features/todo_lists/edit_spec.rb:14:in `update_todo_list'
 # ./spec/features/todo_lists/edit_spec.rb:54:in `block (2 levels) in <top (required)>'

7) Editing todo lists displays an error with no description
 Failure/Error: within "#todo_list_#{todo_list.id}" do
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/features/todo_lists/edit_spec.rb:14:in `update_todo_list'
 # ./spec/features/todo_lists/edit_spec.rb:49:in `block (2 levels) in <top (required)>'

8) Editing todo lists displays an error with no title
 Failure/Error: within "#todo_list_#{todo_list.id}" do
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/features/todo_lists/edit_spec.rb:14:in `update_todo_list'
 # ./spec/features/todo_lists/edit_spec.rb:36:in `block (2 levels) in <top (required)>'

9) Deleting todo lists is successful when clicking the destroy link
 Failure/Error: within "#todo_list_#{todo_list.id}" do
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/features/todo_lists/destroy_spec.rb:9:in `block (2 levels) in <top (required)>'

10) todo_lists/index renders a list of todo_lists
 Failure/Error: assert_select "tr>td", :text => "Title".to_s, :count => 2
 Minitest::Assertion:
   Expected exactly 2 elements matching "tr > td", found 0..
   Expected: 2
     Actual: 0
 # ./spec/views/todo_lists/index.html.erb_spec.rb:20:in `block (2 levels) in <top (required)>'

11) Completing todo items is successful when marking a single item complete
 Failure/Error: visit_todo_list todo_list
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/support/todo_list_helpers.rb:4:in `visit_todo_list'
 # ./spec/features/todo_items/complete_spec.rb:9:in `block (2 levels) in <top (required)>'

12) Completing todo items with completed items shows completed items as complete
 Failure/Error: visit_todo_list todo_list
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/support/todo_list_helpers.rb:4:in `visit_todo_list'
 # ./spec/features/todo_items/complete_spec.rb:21:in `block (3 levels) in <top (required)>'

13) Completing todo items with completed items does not give the option to make complete
 Failure/Error: visit_todo_list todo_list
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/support/todo_list_helpers.rb:4:in `visit_todo_list'
 # ./spec/features/todo_items/complete_spec.rb:28:in `block (3 levels) in <top (required)>'

14) Viewing todo items displays the title of the todo list
 Failure/Error: visit_todo_list(todo_list)
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/support/todo_list_helpers.rb:4:in `visit_todo_list'
 # ./spec/features/todo_items/index_spec.rb:8:in `block (2 levels) in <top (required)>'

15) Viewing todo items displays item content when a todo list has items
 Failure/Error: visit_todo_list(todo_list)
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/support/todo_list_helpers.rb:4:in `visit_todo_list'
 # ./spec/features/todo_items/index_spec.rb:23:in `block (2 levels) in <top (required)>'

16) Viewing todo items displays no items when a todo list is empty
 Failure/Error: visit_todo_list(todo_list)
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/support/todo_list_helpers.rb:4:in `visit_todo_list'
 # ./spec/features/todo_items/index_spec.rb:15:in `block (2 levels) in <top (required)>'

17) Adding todo items is successful with valid content
 Failure/Error: visit_todo_list(todo_list)
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/support/todo_list_helpers.rb:4:in `visit_todo_list'
 # ./spec/features/todo_items/create_spec.rb:9:in `block (2 levels) in <top (required)>'

18) Adding todo items displays an error with content les than 2 characters long
 Failure/Error: visit_todo_list(todo_list)
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/support/todo_list_helpers.rb:4:in `visit_todo_list'
 # ./spec/features/todo_items/create_spec.rb:31:in `block (2 levels) in <top (required)>'

19) Adding todo items displays an error with no content
 Failure/Error: visit_todo_list(todo_list)
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/support/todo_list_helpers.rb:4:in `visit_todo_list'
 # ./spec/features/todo_items/create_spec.rb:20:in `block (2 levels) in <top (required)>'

20) Deleting todo items is successful
 Failure/Error: visit_todo_list(todo_list)
 Capybara::ElementNotFound:
   Unable to find css "#todo_list_1"
 # ./spec/support/todo_list_helpers.rb:4:in `visit_todo_list'
 # ./spec/features/todo_items/delete_spec.rb:9:in `block (2 levels) in <top (required)>'

这是我的./spec/support/todo_list_helpers.rb:4

的列表
module TodoListHelpers
def visit_todo_list(list)
    visit "/todo_lists"
    within dom_id_for(list) do
        click_link "List Items"
    end
  end
end 

这是我的./spec/views/todo_lists/index.html.erb_spec

的列表

要求&#39; spec_helper&#39;

describe "Deleting todo lists" do
    let!(:todo_list) { TodoList.create(title: "Groceries", description: "Grocery list.") }

    it "is successful when clicking the destroy link" do
        visit "/todo_lists"

        within "#todo_list_#{todo_list.id}" do
            click_link "Destroy"
        end
        expect(page).to_not have_content(todo_list.title)
        expect(TodoList.count).to eq(0)
        end
    end

这是我的./spec/views/todo_lists/index.html.erb_spec

的列表

要求&#39; spec_helper&#39;

describe "todo_lists/index" do
  before(:each) do
    assign(:todo_lists, [
      stub_model(TodoList,
        :title => "Title",
        :description => "MyText"
  ),
  stub_model(TodoList,
    :title => "Title",
    :description => "MyText"
  )
])
  end

  it "renders a list of todo_lists" do
    render
    # Run the generator again with the --webrat flag if you want to use webrat matchers
    assert_select "tr>td", :text => "Title".to_s, :count => 2
    assert_select "tr>td", :text => "MyText".to_s, :count => 2
   end
 end

***这是我的app / views / todo_lists / index.html.erb

<h1>Todo Lists</h1>


<% @todo_lists.each do |todo_list| %>
<div class="todo_list" id"<%= dom_id(todo_list) %>">
    <h2><%= todo_list.title %></h2>
    <p><%= todo_list.description %></p>
    <ul class="functions">
        <li><%= link_to "List Items", todo_list_todo_items_path(todo_list) %></li>
        <li><%= link_to 'Show', todo_list %></li>
        <li><%= link_to 'Edit', edit_todo_list_path(todo_list) %></li>
        <li><%= link_to 'Destroy', todo_list, method: :delete, data: { confirm: 'Are you sure?' } %></li>
    </ul>

    <br class="clear" />
 </div>
  <% end %>

 <br>

 <%= link_to 'New Todo list', new_todo_list_path %>

1 个答案:

答案 0 :(得分:0)

知道了!在id

之后忘记了=

我有

id"<%= dom_id

需要

id="<%= dom_id