Hey all,
I've got some code that I (mostly) inherited. It essentially has a
couple of AR class methods that look for a specific record by id:
class Project < ActiveRecord::Base
class << self
def specific_project
@another_specific_project ||= Project.find(10) if
Project.exists?(10)
end
def another_specific_project
@specific_project ||= Project.find(11) if Project.exists?(11)
end
end
end
Typically, when I've specced this code (or more accurately, code that
uses it), I've stubbed out those methods to return a mocked model.
Lately, I've started using cucumber and adding stories for areas we're
adding features to or finding regressions in. From what I can tell, I
can't stub or mock anything from within cucumber step files. Realizing
that the pattern is a bit of code smell, I feel like I have two
directions I could go:
1. Is there a way to stub out the model to return some fixture-type
records?
2. Does anyone have an idea as to how we could refactor this into a
better pattern? Those 2 "projects" are pretty specific to the
production data and will "never be edited," but it still doesn't make
me comfortable.
I'm not sure how to phrase this better. Let me know what other detail
I can provide to make it more clear what I'm looking for.
thanks,
tim
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users