React and Capybara / Rspec

I have a Rails app and am slowly dropping some basic React components in here and there.

My feature tests don’t see the rendered react components in the DOM. I spent some time looking into this, and there is a lot of different advice out there. I tried using selenium, but still have no luck.

To those of you using React components in some of your rails views (maybe I’m alone in this), how do you handle integration testing, or do you?

thanks!

I am using React in my current work and it works perfectly with CapybaraWebkit. Are you setting js: true in your feature specs, along with a configured js driver?

1 Like

Well, I’ve been through the spec_helper a million ways, and my feature test is very simple. I tried with capybara, selenium, and just now the phantomjs driver. same problem: save_and_open shows the unrendered react component placeholder.

Can you paste your test and maybe your spec helper? It could also be useful to point out the versions of your dependencies. I assume it is all good in development/production?

I went through this a few months back and it was an issue with qt4 on my os x machine. here are my notes. installing QT5 fixed it, but I remember the install being a bit tricky.

1 Like

Ok I’ll paste what I have here. I’ve spent two days trying to figure this out and I think I am missing something simple.

here is the test; pretty simple.

require 'spec_helper'

feature 'User manages member/challenge' do
  let(:user) {create(:user)}

  before(:each) do
    login(user)
  end

  scenario 'User is able to log todays reading', :js => true do
    challenge = create(:challenge_with_readings, chapters_to_read: "Matthew 1")
    ChallengeCompletion.new(challenge)
    create(:membership, challenge: challenge, user: user)

    visit member_challenge_path(challenge)
    click_link "Log #{challenge.readings.first.book_and_chapter}"

    expect(MembershipReading.count).to eq 1
  end
end

And here is the spec helper:

require 'rubygems'

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
#require Rails.root.join("db/seeds.rb")
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara/poltergeist'
require 'shoulda/matchers'
require 'email_spec'
require 'sidekiq/testing'

Time.zone = 'Eastern Time (US & Canada)'

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

# Disable Sidekiq will NOT process message
RSpec::Sidekiq.configure do |config|
  config.warn_when_jobs_not_processed_by_sidekiq = false
end

Capybara.javascript_driver = :webkit

RSpec.configure do |config|

  #clears jobs in in worker array before each
  config.before(:each) do
    Sidekiq::Worker.clear_all
    ActionMailer::Base.deliveries.clear
  end

  # suppress error backtrace if related to rvm or rbenv
  config.backtrace_exclusion_patterns = [/\.rvm/, /\.rbenv/, /\.gem/]

  config.infer_spec_type_from_file_location! 
  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  config.use_transactional_fixtures = false

  config.before :suite do
    DatabaseCleaner.clean_with(:truncation, {except: %w[chapters verses]})
  end

  config.before :each do |example|
    if example.metadata[:js]
      DatabaseCleaner.strategy = :truncation, {except: %w[chapters verses]}
    else
      DatabaseCleaner.strategy = :transaction
    end
    DatabaseCleaner.start
  end

  config.after :each do
    DatabaseCleaner.clean
    Timecop.return
  end

  config.infer_base_class_for_anonymous_controllers = false

  config.filter_run focus: true
  config.run_all_when_everything_filtered = true

  # Include Factory Girl syntax to simplify calls to factories
  config.include FactoryGirl::Syntax::Methods

  # Run specs in random order to surface order dependencies. If you find an
  # order dependency and want to debug it, you can fix the order by providing
  # the seed, which is printed after each run.
  #     --seed 1234
  #config.order = "random"
  config.include Devise::TestHelpers, type: :controller
  config.include FeatureHelpers, type: :feature
  config.include Capybara::DSL

  # Include custom macros here
  config.include LoginMacros
  config.include CreationMacros
  config.include ControllerMacros, type: :controller
end

and…here is the Gemfile.lock. sorry for the wall of text

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (4.2.1)
      actionpack (= 4.2.1)
      actionview (= 4.2.1)
      activejob (= 4.2.1)
      mail (~> 2.5, >= 2.5.4)
      rails-dom-testing (~> 1.0, >= 1.0.5)
    actionpack (4.2.1)
      actionview (= 4.2.1)
      activesupport (= 4.2.1)
      rack (~> 1.6)
      rack-test (~> 0.6.2)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.1)
    actionpack-action_caching (1.1.1)
      actionpack (>= 4.0.0, < 5.0)
    actionpack-page_caching (1.0.2)
      actionpack (>= 4.0.0, < 5)
    actionview (4.2.1)
      activesupport (= 4.2.1)
      builder (~> 3.1)
      erubis (~> 2.7.0)
      rails-dom-testing (~> 1.0, >= 1.0.5)
      rails-html-sanitizer (~> 1.0, >= 1.0.1)
    activejob (4.2.1)
      activesupport (= 4.2.1)
      globalid (>= 0.3.0)
    activemodel (4.2.1)
      activesupport (= 4.2.1)
      builder (~> 3.1)
    activerecord (4.2.1)
      activemodel (= 4.2.1)
      activesupport (= 4.2.1)
      arel (~> 6.0)
    activerecord-deprecated_finders (1.0.4)
    activerecord-import (0.8.0)
      activerecord (>= 3.0)
    activesupport (4.2.1)
      i18n (~> 0.7)
      json (~> 1.7, >= 1.7.7)
      minitest (~> 5.1)
      thread_safe (~> 0.3, >= 0.3.4)
      tzinfo (~> 1.1)
    acts_as_scriptural (0.0.5)
    addressable (2.3.8)
    airbrake (4.2.1)
      builder
      multi_json
    annotate (2.6.10)
      activerecord (>= 3.2, <= 4.3)
      rake (~> 10.4)
    ansi (1.5.0)
    arel (6.0.0)
    autoprefixer-rails (5.2.1)
      execjs
      json
    aws-sdk (1.64.0)
      aws-sdk-v1 (= 1.64.0)
    aws-sdk-v1 (1.64.0)
      json (~> 1.4)
      nokogiri (>= 1.4.4)
    bcrypt (3.1.10)
    better_errors (2.1.1)
      coderay (>= 1.0.0)
      erubis (>= 2.6.6)
      rack (>= 0.9.0)
    bootstrap-datepicker-rails (1.1.1.9)
      railties (>= 3.0)
    bootstrap-sass (3.0.2.1)
      sass (~> 3.2)
    bootstrap_form (2.3.0)
    bootswatch-rails (3.3.4)
      railties (>= 3.1)
    builder (3.2.2)
    capybara (2.4.4)
      mime-types (>= 1.16)
      nokogiri (>= 1.3.3)
      rack (>= 1.0.0)
      rack-test (>= 0.5.4)
      xpath (~> 2.0)
    capybara-webkit (1.5.2)
      capybara (>= 2.3.0, < 2.5.0)
      json
    celluloid (0.16.0)
      timers (~> 4.0.0)
    childprocess (0.5.6)
      ffi (~> 1.0, >= 1.0.11)
    climate_control (0.0.3)
      activesupport (>= 3.0)
    cliver (0.3.2)
    cocaine (0.5.7)
      climate_control (>= 0.0.3, < 1.0)
    coderay (1.1.0)
    coffee-rails (4.1.0)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0, < 5.0)
    coffee-script (2.4.1)
      coffee-script-source
      execjs
    coffee-script-source (1.9.1.1)
    connection_pool (2.2.0)
    daemons (1.2.2)
    database_cleaner (1.2.0)
    devise (3.5.1)
      bcrypt (~> 3.0)
      orm_adapter (~> 0.1)
      railties (>= 3.2.6, < 5)
      responders
      thread_safe (~> 0.1)
      warden (~> 1.2.3)
    diff-lcs (1.2.5)
    dotenv (2.0.1)
    dotenv-rails (2.0.1)
      dotenv (= 2.0.1)
    draper (2.1.0)
      actionpack (>= 3.0)
      activemodel (>= 3.0)
      activesupport (>= 3.0)
      request_store (~> 1.0)
    email_spec (1.6.0)
      launchy (~> 2.1)
      mail (~> 2.2)
    erubis (2.7.0)
    es5-shim-rails (4.0.1)
      actionpack (>= 3.1)
      railties (>= 3.1)
    eventmachine (1.0.7)
    execjs (2.5.2)
    factory_girl (4.1.0)
      activesupport (>= 3.0.0)
    factory_girl_rails (4.1.0)
      factory_girl (~> 4.1.0)
      railties (>= 3.0.0)
    faker (1.4.3)
      i18n (~> 0.5)
    faraday (0.9.1)
      multipart-post (>= 1.2, < 3)
    ffi (1.9.8)
    figaro (1.1.1)
      thor (~> 0.14)
    font-awesome-rails (4.3.0.0)
      railties (>= 3.2, < 5.0)
    friendly_id (5.1.0)
      activerecord (>= 4.0.0)
    get_process_mem (0.2.0)
    globalid (0.3.5)
      activesupport (>= 4.1.0)
    google-instant-hangouts (0.0.3)
      railties (>= 3.1)
    gretel (3.0.8)
      rails (>= 3.2.0)
    haml (4.0.6)
      tilt
    haml-rails (0.9.0)
      actionpack (>= 4.0.1)
      activesupport (>= 4.0.1)
      haml (>= 4.0.6, < 5.0)
      html2haml (>= 1.0.1)
      railties (>= 4.0.1)
    hashie (3.4.2)
    high_voltage (2.3.0)
    hirb (0.7.3)
    hitimes (1.2.2)
    hpricot (0.8.6)
    html2haml (2.0.0)
      erubis (~> 2.7.0)
      haml (~> 4.0.0)
      nokogiri (~> 1.6.0)
      ruby_parser (~> 3.5)
    htmlentities (4.3.3)
    httpauth (0.2.1)
    i18n (0.7.0)
    intercom-rails (0.2.28)
      activesupport (> 3.0)
    jquery-rails (4.0.4)
      rails-dom-testing (~> 1.0)
      railties (>= 4.2.0)
      thor (>= 0.14, < 2.0)
    json (1.8.3)
    jwt (0.1.6)
      multi_json (>= 1.0)
    kgio (2.9.3)
    launchy (2.4.3)
      addressable (~> 2.3)
    letter_opener (1.4.1)
      launchy (~> 2.2)
    letter_opener_web (1.3.0)
      actionmailer (>= 3.2)
      letter_opener (~> 1.0)
      railties (>= 3.2)
    loofah (2.0.2)
      nokogiri (>= 1.5.9)
    mail (2.6.3)
      mime-types (>= 1.16, < 3)
    mail_view (2.0.4)
      tilt
    method_source (0.8.2)
    mime-types (1.25.1)
    mimemagic (0.3.0)
    mini_portile (0.6.2)
    minitest (5.7.0)
    multi_json (1.0.4)
    multipart-post (2.0.0)
    nokogiri (1.6.6.2)
      mini_portile (~> 0.6.0)
    oauth2 (0.8.1)
      faraday (~> 0.8)
      httpauth (~> 0.1)
      jwt (~> 0.1.4)
      multi_json (~> 1.0)
      rack (~> 1.2)
    omniauth (1.2.2)
      hashie (>= 1.2, < 4)
      rack (~> 1.0)
    omniauth-facebook (1.6.0)
      omniauth-oauth2 (~> 1.1)
    omniauth-google-oauth2 (0.2.6)
      omniauth (> 1.0)
      omniauth-oauth2 (~> 1.1)
    omniauth-oauth2 (1.1.1)
      oauth2 (~> 0.8.0)
      omniauth (~> 1.0)
    orm_adapter (0.5.0)
    paperclip (4.3.0)
      activemodel (>= 3.2.0)
      activesupport (>= 3.2.0)
      cocaine (~> 0.5.5)
      mime-types
      mimemagic (= 0.3.0)
    pg (0.18.2)
    pg_search (1.0.4)
      activerecord (>= 3.1)
      activesupport (>= 3.1)
      arel
    pickadate-rails (3.5.6.0)
      railties (>= 3.1.0)
    poltergeist (1.6.0)
      capybara (~> 2.1)
      cliver (~> 0.3.1)
      multi_json (~> 1.0)
      websocket-driver (>= 0.2.0)
    pry (0.10.1)
      coderay (~> 1.1.0)
      method_source (~> 0.8.1)
      slop (~> 3.4)
    pry-nav (0.2.4)
      pry (>= 0.9.10, < 0.11.0)
    quiet_assets (1.1.0)
      railties (>= 3.1, < 5.0)
    rack (1.6.2)
    rack-protection (1.5.3)
      rack
    rack-test (0.6.3)
      rack (>= 1.0)
    rack-timeout (0.2.4)
    rails (4.2.1)
      actionmailer (= 4.2.1)
      actionpack (= 4.2.1)
      actionview (= 4.2.1)
      activejob (= 4.2.1)
      activemodel (= 4.2.1)
      activerecord (= 4.2.1)
      activesupport (= 4.2.1)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.2.1)
      sprockets-rails
    rails-deprecated_sanitizer (1.0.3)
      activesupport (>= 4.2.0.alpha)
    rails-dom-testing (1.0.6)
      activesupport (>= 4.2.0.beta, < 5.0)
      nokogiri (~> 1.6.0)
      rails-deprecated_sanitizer (>= 1.0.1)
    rails-html-sanitizer (1.0.2)
      loofah (~> 2.0)
    rails-observers (0.1.2)
      activemodel (~> 4.0)
    rails_12factor (0.0.3)
      rails_serve_static_assets
      rails_stdout_logging
    rails_serve_static_assets (0.0.4)
    rails_stdout_logging (0.0.3)
    railties (4.2.1)
      actionpack (= 4.2.1)
      activesupport (= 4.2.1)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    raindrops (0.13.0)
    rake (10.4.2)
    react-rails (1.0.0)
      coffee-script-source (~> 1.8)
      connection_pool
      execjs
      rails (>= 3.1)
      react-source (~> 0.13)
    react-source (0.13.3)
    redcarpet (3.3.1)
    redis (3.2.1)
    redis-namespace (1.5.2)
      redis (~> 3.0, >= 3.0.4)
    request_store (1.1.0)
    responders (2.1.0)
      railties (>= 4.2.0, < 5)
    rspec (3.3.0)
      rspec-core (~> 3.3.0)
      rspec-expectations (~> 3.3.0)
      rspec-mocks (~> 3.3.0)
    rspec-collection_matchers (1.1.2)
      rspec-expectations (>= 2.99.0.beta1)
    rspec-core (3.3.0)
      rspec-support (~> 3.3.0)
    rspec-expectations (3.3.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.3.0)
    rspec-mocks (3.3.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.3.0)
    rspec-rails (3.3.1)
      actionpack (>= 3.0, < 4.3)
      activesupport (>= 3.0, < 4.3)
      railties (>= 3.0, < 4.3)
      rspec-core (~> 3.3.0)
      rspec-expectations (~> 3.3.0)
      rspec-mocks (~> 3.3.0)
      rspec-support (~> 3.3.0)
    rspec-sidekiq (2.0.0)
      rspec (~> 3.0, >= 3.0.0)
      sidekiq (>= 2.4.0)
    rspec-support (3.3.0)
    ruby_array_find_consecutive (0.0.3)
    ruby_parser (3.7.0)
      sexp_processor (~> 4.1)
    rubyzip (1.1.7)
    sass (3.4.14)
    sass-rails (5.0.3)
      railties (>= 4.0.0, < 5.0)
      sass (~> 3.1)
      sprockets (>= 2.8, < 4.0)
      sprockets-rails (>= 2.0, < 4.0)
      tilt (~> 1.1)
    selenium-webdriver (2.46.2)
      childprocess (~> 0.5)
      multi_json (~> 1.0)
      rubyzip (~> 1.0)
      websocket (~> 1.0)
    sexp_processor (4.6.0)
    shoulda-matchers (2.8.0)
      activesupport (>= 3.0.0)
    sidekiq (3.3.4)
      celluloid (>= 0.16.0)
      connection_pool (>= 2.1.1)
      json
      redis (>= 3.0.6)
      redis-namespace (>= 1.3.1)
    sidekiq-failures (0.4.4)
      sidekiq (>= 2.16.0)
    simple_form (3.1.0)
      actionpack (~> 4.0)
      activemodel (~> 4.0)
    simple_token_authentication (1.10.0)
      actionmailer (>= 3.2.6, < 5)
      actionpack (>= 3.2.6, < 5)
      devise (~> 3.2)
    simplecov (0.5.4)
      multi_json (~> 1.0.3)
      simplecov-html (~> 0.5.3)
    simplecov-html (0.5.3)
    sinatra (1.4.6)
      rack (~> 1.4)
      rack-protection (~> 1.4)
      tilt (>= 1.3, < 3)
    skylight (0.6.1)
      activesupport (>= 3.0.0)
    slop (3.6.0)
    spring (1.3.6)
    spring-commands-rspec (1.0.4)
      spring (>= 0.9.1)
    sprockets (3.2.0)
      rack (~> 1.0)
    sprockets-rails (2.3.1)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      sprockets (>= 2.8, < 4.0)
    sqlite3 (1.3.10)
    thin (1.6.3)
      daemons (~> 1.0, >= 1.0.9)
      eventmachine (~> 1.0)
      rack (~> 1.0)
    thor (0.19.1)
    thread_safe (0.3.5)
    tilt (1.4.1)
    timecop (0.7.4)
    timers (4.0.1)
      hitimes
    turn (0.9.6)
      ansi
    tzinfo (1.2.2)
      thread_safe (~> 0.1)
    uglifier (2.7.1)
      execjs (>= 0.3.0)
      json (>= 1.8.0)
    unicorn (4.9.0)
      kgio (~> 2.6)
      rack
      raindrops (~> 0.7)
    unicorn-worker-killer (0.4.3)
      get_process_mem (~> 0)
      unicorn (~> 4)
    warden (1.2.3)
      rack (>= 1.0)
    websocket (1.2.2)
    websocket-driver (0.6.2)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.2)
    xpath (2.0.0)
      nokogiri (~> 1.3)

PLATFORMS
  ruby

DEPENDENCIES
  actionpack-action_caching
  actionpack-page_caching
  activerecord-deprecated_finders
  activerecord-import
  acts_as_scriptural (= 0.0.5)
  airbrake
  annotate
  autoprefixer-rails
  aws-sdk (~> 1.6)
  better_errors
  bootstrap-datepicker-rails (= 1.1.1.9)
  bootstrap-sass (~> 3.0.2.0)
  bootstrap_form
  bootswatch-rails
  capybara
  capybara-webkit
  coffee-rails
  database_cleaner (~> 1.2.0)
  devise
  dotenv-rails
  draper
  email_spec
  es5-shim-rails
  factory_girl_rails (= 4.1.0)
  faker (~> 1.4.3)
  figaro
  font-awesome-rails
  friendly_id
  google-instant-hangouts
  gretel
  haml
  haml-rails
  high_voltage
  hirb
  hpricot
  htmlentities
  intercom-rails
  jquery-rails
  launchy
  letter_opener
  letter_opener_web
  mail_view
  omniauth
  omniauth-facebook
  omniauth-google-oauth2
  paperclip
  pg
  pg_search
  pickadate-rails
  poltergeist
  pry
  pry-nav
  quiet_assets
  rack-timeout
  rails (= 4.2.1)
  rails-observers
  rails_12factor
  react-rails
  redcarpet
  rspec-collection_matchers
  rspec-rails
  rspec-sidekiq
  ruby_array_find_consecutive
  ruby_parser
  sass-rails
  selenium-webdriver
  shoulda-matchers
  sidekiq
  sidekiq-failures
  simple_form
  simple_token_authentication (~> 1.0)
  simplecov (= 0.5.4)
  sinatra
  skylight
  spring-commands-rspec
  sqlite3
  thin
  timecop
  turn
  uglifier (>= 1.0.3)
  unicorn
  unicorn-worker-killer