Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A few things I thought of, reading your code:</p> <p>You don't need to include parens on method calls taking no arguments. Just <code>http_success</code> will work.</p> <p>You should get try to use the modern RSpec expectation syntax consistently. Instead of <code>assigns(:app).should eq(app)</code>, use <code>expect(assigns(:app)).to eq(app)</code>. (There's one exception to this, which is expectations on mocks (ie. <code>should_receive(:message)</code>), which will only take on the modern expect-to syntax as of <a href="http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3" rel="nofollow">RSpec 3</a>.</p> <p>For controller specs, I like to create little methods for each action that actually invokes the action. You'll notice you call <code>get :show, id: app</code> several times in the <code>GET #show</code> specs. To DRY up your specs a little more, you could instead write the following method within the <code>describe</code> block:</p> <pre><code>def show! get :show, id: app end </code></pre> <p>Try to use one Hash syntax consistently. What's more, Rails 4 can't be run with Ruby 1.8, so there's (nearly) no reason to use the hash-rocket Hash syntax.</p> <p>If I'm getting really, really picky, I usually consider instance variables in a spec to be a smell. In almost all cases, instance variables should be refactored to a memoized <code>let</code>/<code>given</code> blocks.</p> <p>If I'm getting really, really, <em>really</em> picky, I prefer to think of controller specs such as yours as strictly a <strong>unit test</strong> of the controller, not an integration test (that's what Capybara is for), and as such you shouldn't be exercising your model layer at all. You should only be testing that your controller is sending the right messages to the model layer. In other words, all the model layer stuff should be stubbed out. For example:</p> <pre><code>describe 'GET #show' do let(:app) { stub(:app) } before do App.stub(:find).and_return(app) end it 'populates @app' do get :show, id: app assigns(:app).should eq(app) end end </code></pre> <p>I know this last is a personal preference, not a metaphysical truth or even necessarily a wide-spread standard convention, so you may choose to take it or leave it. I prefer it, because it keeps my specs very speedy, and gives me a very clear heuristic for when my controller actions are doing too much, and I might need to consider refactoring. It could be a good habit to get into.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload