RAILS自動試験環境配置
5802 ワード
もっと読む
gemfile
2.
4.
9.最後にtestフォルダを削除することを忘れないでください。そうでないとtest:uiitを起動します。
10.macであれば.rspecに参加します。
gemfile
# source 'https://rubygems.org'
source 'http://ruby.taobao.org'
ruby '2.1.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.7'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
# gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
# gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails', '3.1.2'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks', '2.5.2'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
group :doc do
gem 'sdoc', '0.4.0', require: false
end
group :development, :test do
gem 'rspec-rails', '3.1.0'
gem 'guard-rspec', '4.3.1'
gem 'spork-rails', '4.0.0'
gem 'guard-spork', github: "wudixiaotie/guard-spork"
gem 'childprocess', '0.5.5'
# Use debugger
gem 'debugger', '1.6.8'
end
group :test do
# gem 'selenium-webdriver', '2.44.0'
gem 'poltergeist', '1.5.1'
gem 'capybara', '2.4.4'
gem 'minitest', '5.4.3'
# Uncomment this line on OS X.
# gem 'rspec-nc', '0.2.0'
# Uncomment these lines on Linux.
# gem 'libnotify', '0.8.4'
# Uncomment these lines on Windows.
# gem 'rb-notifu', '0.0.4'
# gem 'win32console', '1.3.2'
# gem 'wdm', '0.1.0'
end
2.
$ rails generate rspec:install
$ bundle exec guard init rspec
3.Gardfileに加入するrequire 'active_support/inflector'
4.
$ bundle exec spork --bootstrap
5.環境コードを追加する Spork.prefork
コードブロック:spec/spec_helper.rbrequire 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# require 'rspec/autorun'
# 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}
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# 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 Capybara::DSL
end
end
Spork.each_run do
# This code will be run each time you run your specs.
end
6.GardとSporkが連携する$ bundle exec guard init spork
7.javascript driverをphantomjsに指定してseleniumの代わりにspecでsupportフォルダを作成し、中にファイルcapybara.rbを追加します。require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
8.修正が終わったら、私達は通過できます。 guard
コマンドはGardとSporkを同時に起動しました。)9.最後にtestフォルダを削除することを忘れないでください。そうでないとtest:uiitを起動します。
10.macであれば.rspecに参加します。
--format Nc
を選択します。