I'm following the rails tutorial, have finished chapter 5 and decided to upgrade from Rails 4 beta1 to the newly released rc2. And the specs now fail.
... application_helper_spec.rb:3:in `<top (required)>':
uninitialized constant ApplicationHelper (NameError)
I've wiped and recreated the spec_helper.rb
file with rm
and bundle exec rspec --init
which solved my first issue. I'm stumped on the second issue which is that the spec isn't finding the application helper I've defined.
Full error output:
tim@atom:~/repo/rails_tutorial_sample_app$ bundle exec rspec
No DRb server is running. Running in local process instead ...
/home/tim/repo/rails_tutorial_sample_app/spec/helpers/application_helper_spec.rb:3:in `<top (required)>': uninitialized constant ApplicationHelper (NameError)
from /home/tim/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
from /home/tim/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
from /home/tim/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from /home/tim/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /home/tim/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from /home/tim/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:77:in `rescue in run'
from /home/tim/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:73:in `run'
from /home/tim/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'
I don't understand how it loads things well enough to troubleshoot it. I read through Rails/RSpec - writing tests for original helper methods and everything this refers to seems in order.
Here are the two apparently relevant files:
spec/helpers/application_helper_spec.rb
require 'spec_helper'
describe ApplicationHelper do
describe "full_title" do
it "should include the page title" do
expect(full_title("foo")).to match(/foo/)
end
it "should include the base title" do
expect(full_title("foo")).to match(/^Ruby on Rails Tutorial Sample App/)
end
it "should not include a bar for the home page" do
expect(full_title("")).not_to match(/\|/)
end
end
end
app/helpers/application_helper.rb
module ApplicationHelper
# full title on per page basis
def full_title(page_title)
base_title = "Ruby on Rails Tutorial Sample App"
if page_title.empty?
base_title
else
"#{base_title} | #{page_title}"
end
end
end
My full sources are at https://github.com/timabell/rails_tutorial_sample_app/tree/4b3d93bbfdb0adb36b87b760c90c3bdda87def16
Halp! I like being in at the deep end but I think I just drowned...