Wednesday, July 22, 2015

how to include Capybara RSpec matchers in RSpec

let say you want to use have_content and have_selector in non rails-helper spec
# Gemfile
gem 'capybara'
gem 'rspec'
# spec/spec_helper.rb
#...
require 'capybara/rspec'
#...
require 'spec_helper'

RSpec.describe MyPresenter do
  include Capybara::RSpecMatchers

  it do 
    expect("<b>abc</b>").to have_selector("b")
  end
end
raw: https://github.com/equivalent/scrapbook2/blob/master/archive/mini-blogs/2015-07-22-capybara-matchers-in-rspec.md