在 Rails 3 (3.0.3) 中的 Test/Unit 下设置 Shoulda

发布于 2024-10-08 07:30:25 字数 1072 浏览 6 评论 0原文

我在其他地方发过这个帖子,但没有回复。尝试让 Shoulda 在 Rails 3.0.3 (1.9.2) 的 Test/Unit 中工作。当我尝试运行测试(复制如下)时,出现此错误:

test/unit/practice_member_test.rb:4:in ': undefined methodcontext' 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 methodcontext' 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

后来的我们 2024-10-15 07:30:25

您是否尝试将以下内容添加到 config/environment.rb 文件中:

  Rails::Initializer.run do |config|
    config.gem "shoulda", :lib => "shoulda"
  end

然后

 $ rake gems:install
 $ rake gems:unpack

按照文档中的建议进行操作?

Did you try adding the following to your config/environment.rb file:

  Rails::Initializer.run do |config|
    config.gem "shoulda", :lib => "shoulda"
  end

Then

 $ rake gems:install
 $ rake gems:unpack

As suggested in the documentation?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文