【发布时间】:2014-04-18 21:02:46
【问题描述】:
我正在关注来自 ruby.railstutorial.org 的 Rails 教程,但不幸的是我现在被难住了。我在第 3 章,其中涉及 rspec 测试。运行以下代码后
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
it "should have the content 'Sample App'" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
visit '/static_pages/home'
expect(page).to have_content('Sample App')
end
it "should have the right title" do
visit '/static_pages/home'
expect(page).to have_title('Ruby on Rails Sample App |Home')
end
describe "Help page" do
it "should have the content 'Help'" do
visit '/static_pages/help'
expect(page).to have_content('Help')
end
it "should have the right title" do
visit '/static_pages/help'
expect(page).to have_title('Ruby on Rails Sample App |Help')
end
describe "About page" do
it "should have the content 'About us'" do
visit '/static_pages/about'
expect(page).to have_content('About us')
end
it "should have the right title" do
visit '/static_pages/about'
expect(page).to have_title('Ruby on Rails Sample App |About')
end
end
我将以下命令传递到我的终端窗口
bundle exec rspec spec/requests/static_pages_spec.rb
我收到以下输出
/Users/name/.rvm/gems/ruby-2.1.0/gems/rspec-core- 2.13.1/lib/rspec/core/configuration.rb:819:in `load': cannot load such file -- /Users/name/MyProjects/sample_app/app/views/spec/requests/static_pages_spec.rb (LoadError)
from /Users/name/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
from /Users/name/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from /Users/name/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /Users/name/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from /Users/name/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
from /Users/name/.rvm/gems/ruby-2.1.0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'
规范在此代码之前运行良好
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
describe "Help page" do
it "should have the content 'Help'" do
visit '/static_pages/help'
expect(page).to have_content('Help')
end
end
describe "About page" do
it "should have the content 'About Us'" do
visit '/static_pages/about'
expect(page).to have_content('About Us')
end
end
end
这是我的 gemfile(感谢昨天帮助我的人)
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.4'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.2'
# 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
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
基本上,我不知道这个输出是什么意思。我也不知道为什么 rspec 不对我的文件执行测试。谁能帮我解决这个问题?
编辑:有什么方法可以在这里编写代码而不用每行缩进 4 个空格?这需要相当长的时间
【问题讨论】:
标签: ruby-on-rails rspec terminal tdd capybara