Rails 2.3.8 机械师未定义方法 make?
我正在开发一个旧的 Rails 2.3.8,它没有任何测试,我正在尝试使用 rspec 和机械师向应用程序添加一些测试。
我已经安装了 rspec 1.3.0 & 1.3.2 并运行生成器脚本。
我按照以下说明进行操作: https://github.com/notahat/machinist/tree/1.0-maintenance
将以下内容添加到 /spec/blueprints.rb
require 'machinist/active_record'
require 'sham'
并将以下行添加到 spec_helper.rb
require File.expand_path(File.dirname(__FILE__) + "/blueprints")
我已经为我的用户创建了一个蓝图,当我尝试使用“User.make!”时在我的spec helper(在登录方法中)中,我收到此错误:
NoMethodError in 'CategoriesController As a logged in user#index should render index'
undefined method `make!' for #<Class:0x7f42b9deea10>
这是我的spec_helper方法:
def login_user
user = User.make!
@request.session[:user_id] = user.id
@current_user ||= User.find_by_id(user.id)
end
自从我接触Rails 2.x应用程序以来已经有一段时间了,所以也许我在这里遗漏了一些东西。
I'm working on an old Rails 2.3.8 which doesn't have any testing and I'm trying to add some tests using rspec with machinist to the app.
I've installed rspec 1.3.0 & 1.3.2 and ran the generator script.
I followed the instructions on:
https://github.com/notahat/machinist/tree/1.0-maintenance
Adding the following to /spec/blueprints.rb
require 'machinist/active_record'
require 'sham'
And the following line to spec_helper.rb
require File.expand_path(File.dirname(__FILE__) + "/blueprints")
I've created a blueprint for my User and when I try to use 'User.make!' in my spec helper (within a login method) I get this error:
NoMethodError in 'CategoriesController As a logged in user#index should render index'
undefined method `make!' for #<Class:0x7f42b9deea10>
Here is my spec_helper method:
def login_user
user = User.make!
@request.session[:user_id] = user.id
@current_user ||= User.find_by_id(user.id)
end
It's been a while since I've touched a Rails 2.x app so maybe I'm missing something here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已解决:
我不应该使用 make!在这个旧版本的机械师中,
我最终为机械师编写了一个小测试,看看它是否会加载我的蓝图,我选择了一个不太复杂的模型,即:一次验证而不是 10 次。
这有效,所以主要与验证和小语法错误。
Solved:
I shouldn't be using make! in this old version of machinist
I ended up writing a little test for machinist to see if it will load my blueprints and I selected a model which is less complicated, ie: one validation not 10.
This worked, so it was mostly to do with validations and small syntax mistakes.