我在运行Rspec时遇到问题:
我的RSpec测试与bundle exec rake spec
正常运行,但bundle exec rspec spec
错误的宝石错误。
我在使用Railsinstaller的Windows 7操作系统上使用Rails 4.1.0
和Ruby 1.9.3p484 (2013-11-22) [i386-mingw32]
。
C:\RailsInstaller\Ruby1.9.3\myapp>bundle exec rspec spec
bundler: command not found: rspec
Install missing gem executables with `bundle install`
当我尝试使用像bundle exec rspec spec/models/project_spec.rb
这样的命令来缩小规范测试时,我的所有测试都会运行,从而大大减慢了我的测试驱动开发速度。我已经在多个Rails项目中使用spec测试重复了这个问题,包括来自我从Github克隆的测试的项目。从Rails 4.0.1降级到Rails 4.0.0并没有解决问题。我的Bundler版本是1.6.2。
我在C:\ RailsInstaller \ Ruby1.9.3 \ lib \ ruby \ gems \ 1.9.1 \ gems中安装了rspec-rails
gem,安装似乎工作正常:
C:\RailsInstaller\Ruby1.9.3\myapp>gem install rspec-rails
Successfully installed rspec-rails-2.14.2
Parsing documentation for rspec-rails-2.14.2
Done installing documentation for rspec-rails after 1 seconds
1 gem installed
bundle exec rake spec
C:\RailsInstaller\Ruby1.9.3\myapp>bundle exec
rake spec ./spec/models/project_spec.rb
C:/RailsInstaller/Ruby1.9.3/bin/ruby.exe -S rspec ./spec/controllers/projects_co
ntroller_spec.rb ./spec/models/project_spec.rb
...FF..
Failures:
1) ProjectsController#create with invalid parameters doesn't create a record t
o the database if title is missing
Failure/Error: post :create, project: {title: "",
NoMethodError:
undefined method `new_url' for #
# ./app/controllers/projects_controller.rb:19:in `create'
# ./spec/controllers/projects_controller_spec.rb:48:in `invalid_params_titl
e'
# ./spec/controllers/projects_controller_spec.rb:58:in `block (5 levels) in
'
# ./spec/controllers/projects_controller_spec.rb:58:in `block (4 levels) in
'
2) ProjectsController#create with invalid parameters doesn't create a record t
o the database if description is missing
Failure/Error: post :create, project: {title: "some valid title",
NoMethodError:
undefined method `new_url' for #
# ./app/controllers/projects_controller.rb:19:in `create'
# ./spec/controllers/projects_controller_spec.rb:53:in `invalid_params_desc
ription'
# ./spec/controllers/projects_controller_spec.rb:62:in `block (5 levels) in
'
# ./spec/controllers/projects_controller_spec.rb:62:in `block (4 levels) in
'
Finished in 0.19601 seconds
7 examples, 2 failures
Failed examples:
rspec ./spec/controllers/projects_controller_spec.rb:57 # ProjectsController#cre
ate with invalid parameters doesn't create a record to the database if title is
missing
rspec ./spec/controllers/projects_controller_spec.rb:61 # ProjectsController#cre
ate with invalid parameters doesn't create a record to the database if descripti
on is missing
Randomized with seed 880
C:/RailsInstaller/Ruby1.9.3/bin/ruby.exe -S rspec ./spec/controllers/projects_co
ntroller_spec.rb ./spec/models/project_spec.rb failed
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.0'
# 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'
# 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', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'bootstrap-sass'
gem 'haml-rails'
gem 'quiet_assets'
gem 'thin'
gem 'simple_form'
gem 'hirb'
#This didn't work either:
#gem 'rspec-rails', group: [:development, :test]
group :development, :test do
gem 'rspec'
gem 'rspec-rails'
gem 'faker'
gem "factory_girl_rails"
gem "capybara"
# gem "capybara-webkit"
gem 'selenium-webdriver', '~> 2.41.0'
gem "database_cleaner"
gem "rails-erd" #use rake erd to create a .dot file you can view current ERD with graphviz
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-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]
bundle install
:
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.1.0)
actionpack (= 4.1.0)
actionview (= 4.1.0)
mail (~> 2.5.4)
actionpack (4.1.0)
actionview (= 4.1.0)
activesupport (= 4.1.0)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
actionview (4.1.0)
activesupport (= 4.1.0)
builder (~> 3.1)
erubis (~> 2.7.0)
activemodel (4.1.0)
activesupport (= 4.1.0)
builder (~> 3.1)
activerecord (4.1.0)
activemodel (= 4.1.0)
activesupport (= 4.1.0)
arel (~> 5.0.0)
activesupport (4.1.0)
i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
bootstrap-sass (3.1.1.1)
sass (~> 3.2)
builder (3.2.2)
capybara (2.2.1)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
childprocess (0.5.3)
ffi (~> 1.0, >= 1.0.11)
choice (0.1.6)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, = 3.0.0)
factory_girl_rails (4.4.1)
factory_girl (~> 4.4.0)
railties (>= 3.0.0)
faker (1.3.0)
i18n (~> 0.5)
ffi (1.9.3-x86-mingw32)
haml (4.0.5)
tilt
haml-rails (0.5.3)
actionpack (>= 4.0.1)
activesupport (>= 4.0.1)
haml (>= 3.1, = 4.0.1)
hike (1.2.3)
hirb (0.7.1)
i18n (0.6.9)
jbuilder (2.0.7)
activesupport (>= 3.0.0, 1.2)
jquery-rails (3.1.0)
railties (>= 3.0, = 0.14, 1.16)
treetop (~> 1.4.8)
mime-types (1.25.1)
mini_portile (0.5.3)
minitest (5.3.3)
multi_json (1.10.0)
nokogiri (1.6.1-x86-mingw32)
mini_portile (~> 0.5.0)
polyglot (0.3.4)
quiet_assets (1.0.2)
railties (>= 3.1, = 1.0)
rails (4.1.0)
actionmailer (= 4.1.0)
actionpack (= 4.1.0)
actionview (= 4.1.0)
activemodel (= 4.1.0)
activerecord (= 4.1.0)
activesupport (= 4.1.0)
bundler (>= 1.3.0, 2.0)
rails-erd (1.1.0)
activerecord (>= 3.0)
activesupport (>= 3.0)
choice (~> 0.1.6)
ruby-graphviz (~> 1.0.4)
railties (4.1.0)
actionpack (= 4.1.0)
activesupport (= 4.1.0)
rake (>= 0.8.7)
thor (>= 0.18.1, 1.4)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.8)
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, = 3.0)
activemodel (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
ruby-graphviz (1.0.9)
rubyzip (1.1.3)
sass (3.2.19)
sass-rails (4.0.3)
railties (>= 4.0.0, 3.2.0)
sprockets (~> 2.8, 2.0)
sdoc (0.4.0)
json (~> 1.8)
rdoc (~> 4.0, = 0.5.0)
multi_json (~> 1.0)
rubyzip (~> 1.0)
websocket (~> 1.0.4)
simple_form (3.0.2)
actionpack (~> 4.0)
activemodel (~> 4.0)
sprockets (2.11.0)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.1.3)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (~> 2.8)
sqlite3 (1.3.9-x86-mingw32)
thin (1.6.2)
daemons (>= 1.0.9)
eventmachine (>= 1.0.0)
rack (>= 1.0.0)
thor (0.19.1)
thread_safe (0.3.3)
tilt (1.4.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
turbolinks (2.2.2)
coffee-rails
tzinfo (1.1.0)
thread_safe (~> 0.1)
tzinfo-data (1.2014.2)
tzinfo (>= 1.0.0)
uglifier (2.5.0)
execjs (>= 0.3.0)
json (>= 1.8.0)
websocket (1.0.7)
xpath (2.0.0)
nokogiri (~> 1.3)
PLATFORMS
x86-mingw32
DEPENDENCIES
bootstrap-sass
capybara
coffee-rails (~> 4.0.0)
database_cleaner
factory_girl_rails
faker
haml-rails
hirb
jbuilder (~> 2.0)
jquery-rails
quiet_assets
rails (= 4.1.0)
rails-erd
rspec
rspec-rails
sass-rails (~> 4.0.3)
sdoc (~> 0.4.0)
selenium-webdriver (~> 2.41.0)
simple_form
sqlite3
thin
turbolinks
tzinfo-data
uglifier (>= 1.3.0)
答案 0 :(得分:1)
请你试试这个。
bundle exec "rspec spec"
或强>
bundle exec rspec
答案 1 :(得分:0)
您需要使用或正在使用的ruby版本不是rspec
正在使用的版本。 rspec
是/usr/bin/rspec
的路径,其第一行令人遗憾
#!/usr/bin/ruby
将您的平台与任何版本/usr/bin/ruby
联系起来。通过更改文件或在路径中先前创建新的rspec
来解决此问题:
#!/usr/bin/env ruby
(在某些系统上,它必须是#!/bin/env ruby
)。
要将rspec与用户本地宝石一起使用(例如,在$HOME/.gem
中),必须指定$GEM_PATH
。基本上rspec
不尊重您的$HOME/.gemrc
文件。
也许bundle exec
解决了上述问题,但对我来说它创造了更多。