While going through the ‘Creating the First Todo’ part of the Test Driven Rails workshop, i added the following in my spec/features/user_creates_todo_spec.rb.
require 'rails_helper' feature 'User creates todo' do scenario 'successfully' do visit root_path click_on 'Add a new todo' fill_in 'Title', with: 'Buy milk' click_on 'Submit' expect(page).to have_css '.todos li', text: 'Buy milk' end end
Then in my app/views/todos/index.html.erb, i added the following:
<%= link_to "Add a new todo", new_todo_path %>
When i run rspec spec/features/user_creates_todo_spec.rb,the test fails with an error Capybara::ElementNotFound: Unable to find link or button “Add a new todo”
However, as per the tutorial im expecting the error to be: Undefined local variable or method ‘new_todo_path’ . But when i run the rails server and navigate to the root path from the browser i see the undefined local variable or method ‘new_todo_path’ error. So, why is it that rspec is showing a different error even though i have the link added to the page ?