How to click first link in list of items after upgrading to Capybara 2.0?

You can just use: first(‘.item’).click_link(‘Agree’) or first(‘.item > a’).click (if your default selector is :css) Code in your question doesn’t work as: within “.item” do first(:link, “Agree”).click end is equivalent to: find(‘.item’).first(:link, “Agree”).click Capybara finds several .item‘s so it raises an exception. I consider this behavior of Capybara 2 very good.

How to get current path with query string using Capybara

I’ve updated this answer to reflect modern conventions in capybara. I think this is ideal since this is the accepted answer, and what many people are being referred to when looking for a solution. With that said, the correct way to check the current path is to use the has_current_path? matcher provided by Capybara, as … Read more

Set up RSpec to test a gem (not Rails)

I’ve updated this answer to match current best practices: Bundler supports gem development perfectly. If you are creating a gem, the only thing you need to have in your Gemfile is the following: source “https://rubygems.org” gemspec This tells Bundler to look inside your gemspec file for the dependencies when you run bundle install. Next up, … Read more

Testing modules in RSpec

The rad way => let(:dummy_class) { Class.new { include ModuleToBeTested } } Alternatively you can extend the test class with your module: let(:dummy_class) { Class.new { extend ModuleToBeTested } } Using ‘let’ is better than using an instance variable to define the dummy class in the before(:each) When to use RSpec let()?

How do I run only specific tests in Rspec?

You can tag examples with :focus hash attribute. For example, # spec/foo_spec.rb RSpec.describe Foo do it ‘is never executed’ do raise “never reached” end it ‘runs this spec’, focus: true do expect(1).to eq(1) end end rspec –tag focus spec/foo_spec.rb More info on GitHub. (anyone with a better link, please advise) (update) RSpec is now superbly … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)