Hi, I have a working application_helper_spec.rb, and now I created a
posts_helper_spec.rb in the spec/helpers directory.
But it looks like rspec is not treating it as a helper spec, the
helper returns null and mocks and stubs are not recognized, and the
before is not being executed, and even my spec_helper.rb is not seeing
it as a :type => :helper
(full source in GitHub - wolfmanjm/wolfmanblog_rails: Wolfman blog ported to rails 3)
Using rspec-rails 2.3.1
the spec is…
require ‘spec_helper’
describe PostsHelper do
before do
@post= mock_model(Post)
end
describe ‘#num_comments with comments’ do
@post.stub(“comments_size”).and_return(10)
helper.num_comments(@post).should == ‘10 comments’
end
describe ‘#num_comments with no comments’ do
@post.stub(“comments_size”).and_return(0)
helper.num_comments(@post).should == ‘no comments’
end
end
rspec spec/helpers/posts_helper_spec.rb
/opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/
activesupport-3.0.3/lib/active_support/whiny_nil.rb:48:in
method_missing': undefined method
stub’ for nil:NilClass
(NoMethodError)
from /home/morris/work/ruby/rails3/wolfmanblog/spec/helpers/
posts_helper_spec.rb:10
from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/
rspec-core-2.3.1/lib/rspec/core/example_group.rb:131:inmodule_eval' from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/example_group.rb:131:in
subclass’
from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/
rspec-core-2.3.1/lib/rspec/core/example_group.rb:118:indescribe' from /home/morris/work/ruby/rails3/wolfmanblog/spec/helpers/ posts_helper_spec.rb:9 from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/example_group.rb:131:in
module_eval’
from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/
rspec-core-2.3.1/lib/rspec/core/example_group.rb:131:insubclass' from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/example_group.rb:118:in
describe’
from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/
rspec-core-2.3.1/lib/rspec/core/extensions/object.rb:6:indescribe' from /home/morris/work/ruby/rails3/wolfmanblog/spec/helpers/ posts_helper_spec.rb:3 from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/configuration.rb:388:in
load’
from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/
rspec-core-2.3.1/lib/rspec/core/configuration.rb:388:in
load_spec_files' from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/configuration.rb:388:in
map’
from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/
rspec-core-2.3.1/lib/rspec/core/configuration.rb:388:in
load_spec_files' from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/command_line.rb:18:in
run’
from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/
rspec-core-2.3.1/lib/rspec/core/runner.rb:55:inrun_in_process' from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/ rspec-core-2.3.1/lib/rspec/core/runner.rb:46:in
run’
from /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/
rspec-core-2.3.1/lib/rspec/core/runner.rb:10:in `autorun’
from /opt/ruby-enterprise-1.8.7-2010.02/bin/rspec:19