&tag(RSpec/Rails3へ導入);
*目次 [#dfe1083a]
#contents
*関連ページ [#x20ce175]
*参考情報 [#ja202bd2]

*使用方法(Rails4編) [#n54af1c0]


**インストール [#b527657d]
-Gemfileに追加
#pre{{
group :development, :test do
  gem "rspec-rails", "~>2.14.0"
  gem "factory_girl_rails", "~>4.2.1"
end

group :test do
  gem "faker", "~>1.1.2"
  gem "capybara", "~>2.1.0"
  gem "database_cleaner", "~>1.0.1"
  gem "launchy", "~>2.3.0"
  gem "selenium-webdriver", "~>2.39.0"
end
}}
-bundle実行
 bundle install --path vendor/bundle
-インストール
#pre{{
 bundle exec rails generate rspec:install
      create  .rspec
      create  spec
      create  spec/spec_helper.rb
}}
-上のように、Gemfileでgroupを指定したときは、config/application.rbを編集する。これでモデルやコントローラーを作成したときに、*_spec.rbファイルを作る挙動を制御できる。
#pre{{
    config.generators do |g|
      g.test_framework :rspec,
        fixtures: true,
        view_specs: false,
        helper_specs: false,
        routing_specs: false,
        controller_specs: true,
        request_specs: false
      g.fixture_replacement :factory_girl, dir: "spec/factories"
    end
}}

※注意事項)
-ちなみに以下のようにgroup指定して、rspec-railsを使う場合、普通にscaffoldするとspecが作られない。
#pre{{
group :development, :test do
  gem "rspec-rails"
end
}}
-これはbundle execの環境がproductionであるため。group指定を以下のようにあらためるか(意味ないけど…)
#pre{{
group :production, :development, :test do
  gem "rspec-rails"
end
}}
-RAILS_ENVを指定する。
 RAILS_ENV=development bundle exec rails g
-でも間違えないように。config/application.rbをいじったほうが簡単。



トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS