私は ruby on rails の初心者です。http://ruby.railstutorial.org/chapters/static-pages#top をチュートリアルとして読んでいます。sample_appバンドルまたはプロジェクトを作成しました。セクション 3.2.1 でアプリをテストしています。まず、cmdから次を実行します
$ rails generate integration_test static_pages
これにより、spec/requests ディレクトリに static_pages_spec.rb が作成されました。次のコードを spec/requests/static_pages_spec.rb に追加します。
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
it "should have the content 'Sample App'" do
visit '/static_pages/home'
expect(page).to have_content('Sample App')
end
end
end
この段階で、次のコードを sample_app/spec/spec_helper.rb ファイルに追加します
config.include Capybara::DSL
私のファイルは次のようになります
# This file is copied to spec/ when you run 'rails generate rspec:install'
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
私は app/views/static_pages/home.html.erb を持っています
<h1>Sample App</h1>
<p>
This is the home page for the
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
sample application.
</p>
コマンドを実行します
$ bundle exec rspec spec/requests/static_pages_spec.rb
それはエラーを出していました
c:/wamp/www/rails_projects/sample_app/spec/spec_helper.rb:42:in `block in <top (
required)>': uninitialized constant Capybara (NameError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core.rb:120:in `configure'
from c:/wamp/www/rails_projects/sample_app/spec/spec_helper.rb:15:in `<t
op (required)>'
from c:/wamp/www/rails_projects/sample_app/spec/requests/static_pages_sp
ec.rb:1:in `require'
from c:/wamp/www/rails_projects/sample_app/spec/requests/static_pages_sp
ec.rb:1:in `<top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/configuration.rb:896:in `load'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/configuration.rb:896:in `each'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/command_line.rb:22:in `run'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/runner.rb:80:in `run'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/runner.rb:17:in `block in autorun'
git step 1->gem install capybara step 2->require 'capybara/rails' in sample_app/spec/spec_helper.rb の指示に従ってカピバラをインストールしましたが、それでもカピバラ レールのロード エラーが表示されました。同じコマンドつまり $ bundle exec rspec spec/requests/static_pages_spec.rb
次のエラーが発生しました
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0/lib/act
ive_support/dependencies.rb:228:in `require': cannot load such file -- capybara/
rspec (LoadError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
4.0.0/lib/active_support/dependencies.rb:228:in `require'
from c:/wamp/www/rails_projects/sample_app/spec/spec_helper.rb:8:in `<to
p (required)>'
from c:/wamp/www/rails_projects/sample_app/spec/requests/static_pages_sp
ec.rb:1:in `require'
from c:/wamp/www/rails_projects/sample_app/spec/requests/static_pages_sp
ec.rb:1:in `<top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/configuration.rb:896:in `load'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/configuration.rb:896:in `each'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/command_line.rb:22:in `run'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/runner.rb:80:in `run'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.1
4.5/lib/rspec/core/runner.rb:17:in `block in autorun'
そして私のgemfileは
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# 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'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
group :development, :test do
gem 'rspec-rails', ">= 2.0.0.beta"
end
gem 'rubyzip'
config.include Capybara::DSL を削除すると、失敗エラーが発生します
正しい方向を教えてください...事前に感謝します