Answer the question
In order to leave comments, you need to log in
Why don't url helpers work in tests?
There is an elementary test
require 'rails_helper'
RSpec.describe "Test if root exists", type: :request do
describe "GET /" do
it "visits root" do
visit root_url
expect(current_url).to eql(root_url)
end
end
end
1) Test if root exists GET / visits root
Failure/Error: visit root_url
NoMethodError:
undefined method `empty?' for nil:NilClass
# ./spec/requests/root_spec.rb:6:in `block (3 levels) in '
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
end
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'spec_helper'
require 'rspec/rails'
require 'capybara/rspec'
require 'factory_girl_rails'
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.include Rails.application.routes.url_helpers
config.infer_spec_type_from_file_location!
config.before(:suite) { DatabaseCleaner.clean_with :truncation }
config.before(:each) { DatabaseCleaner.strategy = :transaction }
config.before(:each, js: true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) { DatabaseCleaner.start }
config.after(:each) { DatabaseCleaner.clean }
config.filter_rails_from_backtrace!
end
Answer the question
In order to leave comments, you need to log in
If you enter a root_url value like '\' and the error persists, then it is not a root_url error.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question