Reputation: 314
When I test one of my spec's, I continue to receive this issue:
Failure/Error: visit "/"
UncaughtThrowError:
uncaught throw :warden
Below are the various sections of code:
#_spec.rb
require "rails_helper"
RSpec.feature "Users can create a new discussion" do
before do
login_as(FactoryGirl.create(:user))
visit "/"
click_link "Discussions"
click_link "Start a discussion"
end
scenario "with valid attributes" do
click_button "Post"
end
end
#_factory.rb
FactoryGirl.define do
factory :user do
sequence(:email) { |n| "test#{n}@example.com" }
password "password"
sequence(:user_name) { |n| "User#{n}" }
first_name "Test"
last_name "User"
country "United States"
state "Nevada"
city "Las Vegas"
end
end
#rails_helper
config.include Warden::Test::Helpers, type: :feature
config.after(type: :feature) { Warden.test_reset! }
Obviously the test is flagging the visit line within the _spec file but I am unsure as to why. If there is any other code I could add to help, please let me know, thank you!
UPDATE
So the issue is because I am using confirmable with Devise; however, it is unclear to me how I could confirm a user through testing. Is this something I could place within the factory or the spec itself? I would think the spec itself?
Upvotes: 0
Views: 289
Reputation: 7482
Just issue a simple .confirm!
on the user, i.e.:
before do
user = FactoryGirl.create(:user)
user.confirm!
login_as(user)
visit "/"
click_link "Discussions"
click_link "Start a discussion"
end
It seems you also lack setting warden
to a test mode (put that into rails_helper):
RSpec.configure do |config|
config.include Warden::Test::Helpers
config.before :suite do
Warden.test_mode!
end
end
See other details here: https://github.com/plataformatec/devise/wiki/How-To%3a-Test-with-Capybara.
Upvotes: 1