4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails3.2にTurnip Capybara Poltergeistを導入してみる

Last updated at Posted at 2014-07-05

前提条件

OS X 10.9.3

Rails3.2にシンプルなBDD環境を整えてみたので備忘録

poltergeist では phantomjs が必要になるようなので brew でインストール

shell
$ brew install phantomjs

Rspecは、2系を選択

Gemfile
group :development, :test do
  gem 'rspec-rails', '2.14'
  gem 'capybara'
  gem "poltergeist"
  gem 'turnip'
end

gem を bundle install して、rspecの初期化を実行する。
feature ファイルと Steps ファイル用のディレクトリを作成

shell
$ bundle install --path vendor/bundler
$ bundle exec rails generate rspec:install
$ mkdir features
$ mkdir steps

.rspec に、パラメーターを追加

.rspec
-r turnip/rspec

spec_helper.rb の "RSpec.configure do |config|"の前あたりに Turnip 関連のファイルをロード

spec/spec_helper.rb
# Turnip settings
Dir.glob("spec/**/*steps.rb") { |f| load f, true }

require 'capybara/dsl'
require 'capybara/rspec'
require 'capybara/poltergeist'
require 'turnip'
require 'turnip/capybara’

# web driver
Capybara.register_driver :poltergeist_debug do |app|
  Capybara::Poltergeist::Driver.new(app, :inspector => true)
end

テストファイルが hogehoge.feature であればテストの実行コマンドは以下のように

$ bundle exec rspec -r turnip/rspec spec/features/hogehoge.feature

Driverに poltergeist を使う場合は、使いたい箇所で current driver に設定する

hogehoge_steps.rb
# encoding: utf-8
Capybara.current_driver = :poltergeist_debug

step 'there is a monster' do
  visit '/monsters'
  page.driver.save_screenshot('/your/evidence/ss_00001.png')
end
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?