0

我正在开发一个没有任何测试的旧 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!”时 在我的规范助手中(在登录方法中)我收到此错误:

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 应用程序以来已经有一段时间了,所以也许我在这里遗漏了一些东西。

4

1 回答 1

0

解决了:

我不应该使用make!在这个旧版本的机械师中

我最终为机械师编写了一个小测试,看看它是否会加载我的蓝图,然后我选择了一个不太复杂的模型,即:一次验证不是 10。

describe "machinist" do
  it "should create a category" do
    category = Category.make
    category.name.should == "General"
  end
end

这行得通,所以它主要与验证和小的语法错误有关。

于 2011-11-17T00:46:39.153 回答