简体   繁体   中英

Rails 4 Rspec Capybara/Selenium : Internal server error

Whenever am trying to go to this path

 localhost:8080/todos

It should go to the todos/index page. Actually this is single page application. So the path would be /todos. But am getting internal server error every time I run my tests. Can someone please help me out!.

My Log file:

    Displaying todos should display the list of todos
 Failure/Error: page.should have_selector('h1', :text => 'Todos')
 Capybara::ExpectationNotMet:
   expected to find css "h1" with text "Todos" but there were no matches
 # ./spec/features/todos/index_spec.rb:26:in `block (2 levels) in <top (required)>'

my controller: todos_controller.rb

     skip_before_action :authenticate_user!

    def index
     @todos_completed_today = current_user.todos.where(is_completed: true).
     where("updated_at >= ?", (Time.zone.now - 24.hours)).order('todos.position ASC')
     @todos = current_user.todos.where(is_completed: false).order('todos.position ASC')
  end

  def create
   @todo = Todo.find(params[:id])
   @todo = current_user.todos.new(todo_params)
   @todo.save
    respond_to do |format|
    format.html { redirect_to todos_path }
    format.js
  end
 end

def edit
 @todo = current_user.todos.find_by_id(params[:id])
end

def update
 @todo = current_user.todos.find_by_id(params[:id])
 @todo.update_attributes(todo_params)
end

def destroy
 @todo = current_user.todos.find_by_id(params[:id])
 @todo.destroy
end

test spec: todos/index_spec.rb

 it "should display the list of todos", :js => true do
visit "/todos"

expect(Todo.count).to eq(0)
page.should have_selector('h1', :text => 'Todos')



fill_in "title", with: "MyString"
click_button "Create"

expect(page).to have_content("Todo has been created!")
expect(todo.todo_title).to eq(title)

todo.reload!
expect(Todo.count).to eq(1)
expect(todo.title).eq("Mystring")

end

Capybara::ExpectationNotMet: expected to find css "h1" with text "Todos" but there were no matches

You haven't supplied your view, but I would be checking to see you have a element with selector h1, that have the contents "Todos"

As per this test you have setup: page.should have_selector('h1', :text => 'Todos')

Alternatively, if you have a h1 element, you can change your test syntax to:

page.should have_tag("h1", :text => "Todos")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM