Skip to content

Instantly share code, notes, and snippets.

@jennli
Last active March 2, 2016 21:44
Show Gist options
  • Save jennli/6381ff3899b631002182 to your computer and use it in GitHub Desktop.
Save jennli/6381ff3899b631002182 to your computer and use it in GitHub Desktop.

Integration Test

  • brew install qt

  • gem 'capybara'

  • gem 'laundry'

  • create a features folder in rspec

 rails g rspec:feature campaigns
  • in rails_helper.rb, include capybara/rails as a required gem
require 'spec_helper'
require 'rspec/rails'
require 'capybara/rails'
  • in spec/features/campaigns_spec.rb
  describe "Campaigns Listing" do
    it "displays a text 'Recent Campaigns'" do
      # this simulates users typing the 'campaign_path' in the address bar
      # to actually visit the page
      visit campaigns_path

      # we have accss to an object 'page' that contains the rendered HTML page
      # 
      expect(page).to have_text "Recent Campaigns"
    end
  end
  • add this line to index.html.erb
<p> Recent Campaigns</p>
  • spec/features/campaigns_spec.rb
  it "displays an h2 header with text 'All Campaigns'" do
      visit campaigns_path
      expect(page).to have_selector "h2", text: "All campaigns"
    end
  • the laundry gem allows a debugging technique
save_and_open_page

this line will pause the test and open the page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment