我已经在我的windows7机器上安装了growl + rspec + autotest。在命令提示符下,当我输入'rspec spec/‘时,它不起作用。只有当我使用'rake spec/‘+ 'autotest’时,测试才会运行。
另外,我正在运行这些测试:http://railstutorial.org/chapters/static-pages#code:default_pages_controller_spec (也就是非常,非常琐碎),它们花费了8.11秒。
当我运行它们时,它们也会失败--即使它们在示例中没有。我已经做了教程告诉我的所有事情,问题是教程没有深入到在Windows机器上安装rspec。它提供了一个链接,但即使这样,你也必须将指令拼凑在一起。
我得到的错误是'Failure/Error: Unable to find C to read failed line [31mundefined methord get' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x48336c0>'
第二个错误与此非常相似。
我也正确地安装了Growl,因为我收到了两次失败的通知。
有谁可以帮我?
发布于 2011-01-13 11:16:09
我用谷歌搜索了一下,根据this thread on the rspec ruby forum和this closed rspec-rails issue的说法,这是rspec-rails的一个问题,已经修复了。
我在Windows7上使用rails 3.0.3运行Ruby 1.9.2p136。
这是我的Gemfile的样子,它显示了我使用的rspec和rspec-rails的版本:
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'sqlite3-ruby', :require => 'sqlite3'
group :development do
gem 'rspec-rails', '2.4.1'
end
group :test do
gem 'rspec', '2.4.0'
gem 'webrat', '0.7.1'
end我之所以说"lookED like“,是因为当我尝试运行rspec rails生成器时,得到的结果是:
C:\Ruby\sample_app>rails generate rspec:install
create .rspec
create spec
create spec/spec_helper.rb
Could not find "autotest" in any of your source paths. Your current source paths
are:
C:/Ruby/sample_app/lib/templates/rspec/install
C:/Ruby/192-stackoverflow/lib/ruby/gems/1.9.1/gems/rspec-rails-2.3.0/lib/generators/rspec/install/templates因此,我将autotest添加到我的Gemfile中(并再次安装包),然后再次尝试rails generate rspec:install,它没有出现任何错误。这就是我的Gemfile现在的样子:
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'sqlite3-ruby', :require => 'sqlite3'
group :development do
gem 'autotest'
gem 'rspec-rails', '2.4.1'
end
group :test do
gem 'rspec', '2.4.0'
gem 'webrat', '0.7.1'
end安装的autotest版本是4.4.6:
C:\Ruby\sample_app>bundle show autotest
C:/Ruby/192-stackoverflow/lib/ruby/gems/1.9.1/gems/autotest-4.4.6然后,我按照教程中的说明创建了控制器:
$ rails generate controller Pages home contact并且我能够运行"bundle exec autotest“和"rspec spec/”而没有得到你所看到的错误:
C:\Ruby\sample_app>bundle exec autotest
loading autotest/rspec2
bundle exec C:\Ruby\192-stackoverflow\bin\ruby -S C:/Ruby/192-stackoverflow/lib/ruby/gems/1.9.1/gems/rspec-core-2.4.0/bin/rspec --tty 'C:/Ruby/sample_app/spec/controllers/pages_controller_spec.rb'
..
Finished in 23.04 seconds
2 examples, 0 failures
# I killed autotest with CTRL-c at this point
Interrupt a second time to quit
Terminate batch job (Y/N)? y
Terminate batch job (Y/N)? y
C:\Ruby\sample_app>rspec spec/
..
Finished in 23.11 seconds
2 examples, 0 failures我还继续了教程,为About页面编写规范,同时autotest正在运行,它运行在我所做的更改上,没有任何问题。
因此,请尝试:
‘的
如果有效的话,请告诉我。我会回来再检查的!
发布于 2012-07-27 23:41:43
我认为这可能会帮助那些现在可能遇到麻烦的人,因为所有的gem都已经更新了很多(特别是对于那些使用Ruby on Rails 3教程的人):
我能够使用所有gem的最新版本来实现这一点:
我的Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.6'
gem 'jquery-rails'
gem 'sqlite3', :group => [:development, :test]
gem 'pg', :group => :production #This is so Heroku will work
group :development do
gem 'rspec-rails'
end
group :test do
gem 'rspec'
gem 'webrat'
gem 'spork-rails' #Use this is only if you want to use spork
end如果您已经有一个较旧的版本(例如,通过使用Ruby on Rails 3教程),请确保您清理了rspec:https://stackoverflow.com/a/4433217/911133
要使用自动测试,请按照以下说明操作:https://github.com/svoop/autotest-growl
请注意,安装用于windows的growl是交易的一部分,snarl是而不是 needed:http://www.growlforwindows.com/
您的.autotest文件可以位于以下两个位置之一
1)您的主目录,例如:
C:\users\joeblow\.autotest2) rails应用程序根目录(这将仅对该应用程序运行)
我的.autotest文件如下所示:
require 'autotest/growl'
require 'autotest/restart'
require 'autotest/timestamp'
Autotest.add_hook :initialize do |autotest|
autotest.add_mapping(%r%^spec/(requrests)/.*rb$%) do
|filename, _|
filename
end
end
Autotest::Growl::clear_terminal = false确保你已经做了一个'bundle install‘
然后运行Growl for windows (开始菜单或windows启动时开始)
在命令行中运行autotest,就可以运行了!
c:\users\joeblow\workspace\Rails\MyRailsProject> autotest发布于 2010-10-04 22:25:26
我还没有找到一个有效的永久修复,但显然它归结为路径问题-某些东西正在吞噬windows路径,然后它就坏了。然而,有一个变通的方法:
在你的describe中,在“get”调用之前,放入如下内容:
包括RSpec::Rails::ControllerExampleGroup
下面是使用为控制器生成的Rails规范的示例代码。请注意,它位于作用域的开头:
require 'spec_helper'
describe PagesController do
include RSpec::Rails::ControllerExampleGroup
describe "GET 'home'" do
it "should be successful" do
get 'home'
response.should be_success
end
end
describe "GET 'contact'" do
it "should be successful" do
get 'contact'
response.should be_success
end
end
end我看到了一个修复,建议对spec_helper (在Rails中)进行更改,但我无法使其正常工作。
编辑:更多的研究表明这是autospec的问题-如果你只使用rspec,这个工作可以解决,但不能使用autotest。然而,我还没有找到解决这个问题的办法。
https://stackoverflow.com/questions/3852143
复制相似问题