从新的 Rails 插件运行 rake:test 时,架构和装置未加载

发布于 2024-12-06 07:04:56 字数 720 浏览 0 评论 0原文

我正在 ruby​​ 1.9.2p290(2011-07-09 修订版 32553)[x86_64-linux] 上使用 Rails 3.1.0 创建一个全新的完整 gem 插件。我在运行 rake 测试时遇到了架构和装置未加载的问题。以下是我正在采取的步骤:

创建插件:

rails plugin new core --full

从插件中生成一个新的脚手架:

rails g scaffold user

运行数据库创建和迁移:

rake db:create
rake db:migrate

运行测试:

rake test

运行功能测试时,我从以下位置收到一组错误:控制器测试:

1) Error:
test_should_create_user(UsersControllerTest):
NoMethodError: undefined method `users' for #<UsersControllerTest:0x00000003babca8>

此错误似乎源于测试似乎不理解夹具调用的事实。测试数据库似乎没有加载架构或加载固定装置。这是预期的行为吗?在这个场景中我缺少什么吗?所有的固定装置都在那里。我需要遵循一些流程才能使这些测试正确运行吗?

I am creating a brand new full gem plugin using Rails 3.1.0 on ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]. I am having trouble with the schema and fixtures not being loaded for running rake test. Following are the steps I am taking:

Create the plugin:

rails plugin new core --full

From the plugin, generate a new scaffold:

rails g scaffold user

Run the db create and migrate:

rake db:create
rake db:migrate

Run the tests:

rake test

When running the functional tests, I am receiving a set of error like the following from the controller tests:

1) Error:
test_should_create_user(UsersControllerTest):
NoMethodError: undefined method `users' for #<UsersControllerTest:0x00000003babca8>

This error seems to stem from the fact that the test doesn't seem to understand the fixture call. It doesn't look like the test db is getting the schema loaded or having the fixtures loaded. Is this expected behavior? Is there something I'm missing in this scenario? All the fixtures are there. Is there some process I need to follow to get these tests to run correctly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

心凉怎暖 2024-12-13 07:04:56

好吧,我想我已经取得了一些进展。看起来我可以通过以下更改来解决它。

我已将以下内容添加到 test_helper:

#Run any available migration
ActiveRecord::Migrator.migrate 'up'

# Set fixtures root
ActiveSupport::TestCase.fixture_path=(File.expand_path("../fixtures",  __FILE__))
ActiveSupport::TestCase.fixtures :all

这允许测试环境在虚拟应用程序之外找到我的装置。

进行此更改后,我仍然遇到一个问题,即测试数据库未准备好进行测试。我通过放入 test/dummy 目录并运行来解决这个问题:

rake db:test:prepare

此后,我能够成功运行“rake test”。必须进入虚拟应用程序来准备数据库有点痛苦。必须有办法解决这个问题。有什么建议吗?

OK, I think I've made some progress. It looks like I can resolve it with the following changes.

I've added the following to test_helper:

#Run any available migration
ActiveRecord::Migrator.migrate 'up'

# Set fixtures root
ActiveSupport::TestCase.fixture_path=(File.expand_path("../fixtures",  __FILE__))
ActiveSupport::TestCase.fixtures :all

This allows the test environment to find my fixtures outside of the dummy application.

After this change, I was still having an issue where the test database was not being prepared for the test. I resolved this by dropping into the test/dummy directory and running:

rake db:test:prepare

After this, I am able to run "rake test" successfully. It's somewhat a pain to have to drop in to the dummy app to prepare the db. There has to be a way around this. Any suggestions?

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