mardi 21 juillet 2015

RSpec - Creating tests for view templates that require IDs

I'm using RSpec and Shoulda Matchers and have gotten to the pointer where I need to test the view templates for my controllers. More specifically I need to test views that require ids:

localhost:3000/restaurants/1

I've taken a look at the example code from Shoulda but doesn't work:

describe PostsController do
  describe 'GET #show' do
    before { get :show }
     it { should render_template('show') }
     it { should render_template(partial: 'sidebar') }
   end
end

On a previous post I was advised to pass an id as a parameter inside the get method.

require "rails_helper"

describe RestaurantsController do
  describe "GET #show" do
    before { get :show, id: 1}

    it { should render_template("show") }
  end
end

For this to work though I would need to create a restaurant factory of some sort. Is there an automated and conventional way I can do this without a factory?

Aucun commentaire:

Enregistrer un commentaire