In my spec, I'm visiting a page and checking that an instance variable is being set correctly. The spec is always saying that the assigns is nil. Looking at the saved page, it's blank—not a 404 or any sort of error page.
describe ArtistsController do
before :each do
@artist = Artist.first
end
describe "GET #about" do
it "finds artist by artistname" do
visit artist_about_path(@artist.artistname); save_page
puts "2 ===================== #{ artist_about_path(@artist.artistname) }"
# assigns(:artist).should eq(@artist)
assigns[:artist].should_not be_nil
end
it "renders the :about view" do
visit artist_about_path(@artist.artistname)
# response.should render_template :about
response.should be_success
end
end
# Similar specs for other pages to be rendered
Artist.first comes from a rake task that's being run in spec_helper to populate the database; that part works correctly in other tests.
I'm checking the path by printing it, and it looks fine. Controller methods:
class ArtistsController < ApplicationController
before_filter :get_artist_from_params
def about
@artist = Artist.find_by_artistname(params[:artistname].downcase)
@contact_info = @artist.contact_info
puts "1 ==============================="
puts @artist.inspect
end
In the server logs, @artist is the object we expect.
def get_artist_from_params
if !params[:artistname].blank?
@artist = Artist.find_by_artistname(params[:artistname].downcase)
if @artist.blank?
not_found
end
end
end
I'm not sure where the test is going wrong…The puts are outputting the right values.
Using Ruby 2.0, Rails 3.2, Capybara 2.1, Rspec 2.12.