how to expect 'render template' error

what to expect when you're expecting film
what to expect app
what to expect when you're expecting pdf
what to expect when you're expecting book
what to expect when you're pregnant
what to expect when you're expecting cast
what to expect when you're expecting amazon
what to expect books

I have a view template "show.html.haml", something like

- if current_user.admin?
  balabala

It will get "undefined method `admin?' for nil:NilClass" while GET #show. I fixed it with " - if !current_user.nil? && current_user.admin?". And I want to add a test case with RSpec.

describe "before login user - " do

  it "render the show template" do
    book = FactoryGirl.create(:book)
    get :show, id: book.id

    expect(response).to render_template("show")
    expect(response).to be_success
  end
end

While run "bin/rake spec", it always get success no matter if I add the condition "!current_user.nil?". How can I write the expect clause while I want to check if rendering 'show' view is sucess?

As you are trying to test content of view from controller spec , you can not do that directly.

You can use render_views declaration to do that but it is not recommended rather you should go for either request spec or feature spec to test the complete request - response cycle.

Setting up render_views globally:

RSpec.configure do |config|
  config.render_views
end

Spec:

describe "before login user - " do
  it "render the show template" do
    book = FactoryGirl.create(:book)
    get :show, id: book.id
    expect(response).to render_template("show")
    expect(response.body).to match /balabala/
  end
end

What to Expect When You're Expecting 5th Edition: Amazon.co.uk , Buy What to Expect When You're Expecting 5th Edition by Murkoff, Heidi (ISBN: 9781471147524) from Amazon's Book Store. Everyday low prices and free� Expect definition, to look forward to; regard as likely to happen; anticipate the occurrence or the coming of: I expect to read it. I expect him later. She expects that they will come.

By default views do not get rendered in controller specs. You need to explicitly enable it by writing render_views (in your describe block). See the reference: https://www.relishapp.com/rspec/rspec-rails/v/3-5/docs/controller-specs/render-views

What to Expect When You're Expecting: Amazon.co.uk: Murkoff , Buy What to Expect When You're Expecting 5th Fifth Edition, Revised ed. by Murkoff, Heidi (ISBN: 9780761187486) from Amazon's Book Store. Everyday low � expect definition: 1. to think or believe something will happen, or someone will arrive: 2. normal and what usually…. Learn more.

You need to "sign in" in your spec. Don't change your code just to make the test passed. Check rendering is successful or not is simple, just check the response status:

expect(response.status).to eq 200

What to Expect When You're Expecting (film), This pregnancy tracker app from the world's most trusted pregnancy brand, "What to Expect When You're Expecting," guides you through� Define expect. expect synonyms, expect pronunciation, expect translation, English dictionary definition of expect. v. ex·pect·ed , ex·pect·ing , ex·pects v. tr. 1. a. To look forward to the probable occurrence or appearance of: expecting a phone call; expects rain on

Add type: :view like so.

describe "before login user - ", type: :view do
  it "render the show template" do
    book = FactoryGirl.create(:book)
    get :show, id: book.id

    expect(response).to render_template("show")
    expect(response).to be_success
  end
end

Pregnancy & Baby Tracker WTE on the App Store, Knowing what physical and emotional changes to expect during the first trimester can help you face the months ahead with confidence. Your body. While your first � Students shouldn't expect to receive their aid until around the time classes start, or maybe a few weeks after. They may have expenses come up in the summer prior to that time, such as textbooks

1st trimester pregnancy: What to expect, Directed by Kirk Jones. With Cameron Diaz, Matthew Morrison, J. Todd Smith, Dennis Quaid. Follows the lives of five interconnected couples as they experience� Synonyms for expect at Thesaurus.com with free online thesaurus, antonyms, and definitions. Find descriptive alternatives for expect.

What to Expect When You're Expecting (2012), The educational health content on What To Expect is reviewed by our medical review board and team of experts to be up-to-date and in line with the latest evidence-based medical information and accepted health guidelines, including the medically reviewed What to Expect books by Heidi Murkoff. This educational content is not medical or diagnostic

Expect is an extension to the Tcl scripting language written by Don Libes.The program automates interactions with programs that expose a text terminal interface. Expect, originally written in 1990 for the Unix platform, has since become available for Microsoft Windows and other systems.