在 Rails 3 (3.0.3) 中的 Test/Unit 下设置 Shoulda
我在其他地方发过这个帖子,但没有回复。尝试让 Shoulda 在 Rails 3.0.3 (1.9.2) 的 Test/Unit 中工作。当我尝试运行测试(复制如下)时,出现此错误:
test/unit/practice_member_test.rb:4:in
context' for PracticeMemberTest:类 (NoMethodError)
请注意,我有另一个带有 Rspec 的 Rails 3 项目,也包括 Shoulda,并且它通过 Rspec 工作得很好。在失败的项目中,我尝试将“require 'shoulda'”放入测试助手中,但无济于事,但是当我运行调试器并输入 Shoulda 时,会找到该对象,因此正在加载库。
这是我的测试:
require 'test_helper'
class PracticeMemberTest <测试::单元::测试用例 上下文“实践成员”做
应该“获取不包括演示实践的全球实践成员数量”吗 assert_equal PracticeMember.practice_members_global_count, 0
practice = Factory.create(:practice_one)
practice_member = Factory.create(:practice_member)
practice_member.practice_id = practice.id
practice_member.save
practice_member = Factory.create(:practice_member)
practice_member.practice_id = practice.id
practice_member.save
assert_equal PracticeMember.practice_members_global_count, 2
end
结束 一定
是我忽略的事情,因为我还没有看到任何人遇到同样的问题。
I have posted this in other places but no response. Trying to get Shoulda working inside Test/Unit in Rails 3.0.3 (1.9.2). When I try to run the test (copied below), I get this error:
test/unit/practice_member_test.rb:4:in <class:PracticeMemberTest>': undefined method
context' for PracticeMemberTest:Class (NoMethodError)
Note that I have another Rails 3 project with Rspec including Shoulda also and it works fine via Rspec. In the failing project I tried placing "require 'shoulda'" in test helper to no avail, but when I run the debugger and type Shoulda, the object is found, so the library is being loaded.
Here is my test:
require 'test_helper'
class PracticeMemberTest < Test::Unit::TestCase
context "practice member" do
should "get global practice member count not including Demo Practice" do
assert_equal PracticeMember.practice_members_global_count, 0
practice = Factory.create(:practice_one)
practice_member = Factory.create(:practice_member)
practice_member.practice_id = practice.id
practice_member.save
practice_member = Factory.create(:practice_member)
practice_member.practice_id = practice.id
practice_member.save
assert_equal PracticeMember.practice_members_global_count, 2
end
end
end
Must be something I am overlooking as I have not seen anyone with this same issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试将以下内容添加到 config/environment.rb 文件中:
然后
按照文档中的建议进行操作?
Did you try adding the following to your config/environment.rb file:
Then
As suggested in the documentation?