0

I just started some tests on my Rails application in which I use Devise for authentication. I just generated rspec and only added

RSpec.configure do |config|
  config.include Devise::TestHelpers, :type => :controller
end

to my spec/support/devise.rb file. I also added Capybara to the test group in my gemfile, run the bundle command, etc. But as I do visit in my tests, I get a no method error. Here an example of my user_spec.rb:

require 'spec_helper'

describe "Club" do
  before(:each) do
    @club ||= FactoryGirl.create(:club)
    FactoryGirl.create(:membership)
    User.all.each{|x| x.delete}
  end
  describe "privacy" do
    it "shouldn't be shown any tournament if the user is private" do
      attributes = FactoryGirl.attributes_for(:user)
      user = User.create!({private: true}.merge(attributes))
      assert(user.private)
      visit "/user/#{user.id}/tournaments"

      page.should have_no_selector(".tournament-list")
    end
  end
end

As I run rspec there comes an error like this:

Failures:

  1) Club privacy shouldn't be shown any tournament if the user is private
     Failure/Error: visit "/user/#{user.id}/tournaments"
     NoMethodError:
       undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_3::Nested_1:0x007ff0ea113108>
     # ./spec/user_spec.rb:14:in `block (3 levels) in <top (required)>'
1

2 Answers 2

1

For capybara specs I use:

describe "Club", :type => :feature, :js => true do
  include Capybara::DSL

  it "..."
end

And instead User.all.each{|x| x.delete}, use DatabaseCleaner

Sign up to request clarification or add additional context in comments.

Comments

1

You can easily add the Capybara::DSL to RSpec config spec_helper.rb

RSpec.configure do |config|
  .....
  .......
  config.include(Capybara::DSL)

end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.