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.
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.