Rails - 让 RSpec 正常工作
我正在学习如何在我的 Rails 应用程序上进行集成测试。我从黄瓜开始,但后来了解到,因为我只是测试模型方法,所以我应该使用 RSPEC。所以现在我正在尝试安装 RSPEC。
当我运行自动测试时,它只查看 /features 目录而不是 /spec 目录。
这是我到目前为止所做的:
.autotest
require 'autotest/growl'
require 'autotest/fsevent'
Autotest.add_hook(:initialize) {|at|
at.add_exception %r{^\.git} # ignore Version Control System
at.add_exception %r{^./tmp} # ignore temp files, lest autotest will run again, and again...
# at.clear_mappings # take out the default (test/test*rb)
at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|
Dir['spec/**/*.rb']
}
nil
}
/spec - created directory
/spec/spec_helper.rb - created
/spec/lib/mailingjob_spec.rb - created, tried to write a case that would fail as follows:
require 'spec_helper'
describe User do
before(:each) do
@valid_attributes = {
:login => "akm",
:email => "[email protected]",
:password => "D1ff1cultPa55w0rd",
:password_confirmation => "D1ff1cultPa55w0rd"
}
end
it "should create a new instance given valid attributes" do
User.create!(@valid_attributesXXXX)
end
end
但是当我运行自动测试时,这个 rpsec 永远不会运行,只有带有 cucumber 的 features 目录正在运行。有想法吗?谢谢
I'm learning how to do integration testin on my rails app. I started with cucumber but then learned since I'm just testing a models method that I should be using RSPEC. So now I'm trying to get RSPEC installed.
When I run autotest, it is only looking at the /features directory not the /spec directory.
Here's what I've done so far:
.autotest
require 'autotest/growl'
require 'autotest/fsevent'
Autotest.add_hook(:initialize) {|at|
at.add_exception %r{^\.git} # ignore Version Control System
at.add_exception %r{^./tmp} # ignore temp files, lest autotest will run again, and again...
# at.clear_mappings # take out the default (test/test*rb)
at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|
Dir['spec/**/*.rb']
}
nil
}
/spec - created directory
/spec/spec_helper.rb - created
/spec/lib/mailingjob_spec.rb - created, tried to write a case that would fail as follows:
require 'spec_helper'
describe User do
before(:each) do
@valid_attributes = {
:login => "akm",
:email => "[email protected]",
:password => "D1ff1cultPa55w0rd",
:password_confirmation => "D1ff1cultPa55w0rd"
}
end
it "should create a new instance given valid attributes" do
User.create!(@valid_attributesXXXX)
end
end
But when I run autotest this rpsec is never run only the features dir with cucumber is running. Ideas? thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
来自自动测试自述文件:
Try:
From the autotest README: