I am trying to make a spec tests, here is the scenario:
scenario 'Authenticated user creates question' do
User.create!(email: 'user@test.com', password: '1234567')
visit new_user_session_path
fill_in 'Email', with: 'user@test.com'
fill_in 'Password', with: '1234567'
click_on 'Log in'
visit questions_path
click_on 'Ask question'
fill_in 'Title', with: 'Test question'
fill_in 'Body', with: 'text text'
click_on 'Create'
expect(page).to have_content 'Your question successfully created.'
end
scenario 'Non-authenticated user tries to create question' do
visit questions_path
click_on 'Ask question'
expect(page).to have_content 'You need to sign in or sign up before continuing.'
end
end
It gives me out an error: "QuestionsController#index is missing a template for request formats: text/html". The problem is that I have an index file but in slim format: index.html.slim And it gives me out another error if I make index file erb: " Unable to find link or button "Ask question" ". So I think that the problem is that my code cannot see slim files. In application.rb I already have this code:
config.generators do |g|
g.template_engine = :slim
end
Here is part of my gemfile:
group :development do
gem 'slim-rails'
end
What may be the problem? Why ruby cannot see my slim files?
The problem is that you have slim-rails
in the development group in your Gemfile and you're running the test environment. I can't possibly think of a scenario where you would actually want different template engines per environment.
Just move it out of the development
group.
gem 'slim-rails', '~> 3.2'
Adding a version constraint is also recommended for something this mission critical if you don't want your app to suddenly break.