Question: I wonder how to validate the locals passed to render template in controller

Controller:

```
def lelf_panel
  # ...
  if some_condition
    locals_hash = some_very_long_hash_A
  else
    locals_hash = some_very_long_hash_B
  end
  render :partial => "left_panel", :layout => false, :locals => locals_hash
end

```

Current Spec:

```
it 'should render correct template for lelf_panel' do
  # ... 
  get 'left_panel'
  response.should render_template('system/_left_panel')
end   

```

Now I need to finish Rcov for this controller so I need to add/modify spec to cover both 'some\_condition' results. and I want to validate 'lelf\_panel' locals passed to render, as if I only validate the render\_template, partial page rendered for both result are the same.

I check the 'render\_template' in rspec docs in 
<http://rubydoc.info/gems/rspec-rails/2.8.1/RSpec/Rails/Matchers/RenderTemplate:render_template>

it only provide and 2nd params for message, so how can I test the locals passed to render?

Answer: 
as far as I know, there is no way to directly examine the locals for a template in the way you're describing.

You could change locals\_hash to @locals\_hash and then examine the results through assigns( :locals\_hash).

Or, you could use selectors on the resulting HTML and check that some indicative content is there -- for instance, if locals\_hash affects the title of the page, check that the resulting HTML page title is what you expect.
Same as @ryan-ahearn 's answer with suggestions from @user2490003 's comment - but all put into something more flexible and for RSpec 3.

```
  # Safe to set globally, since actions can either render or redirect once or fail anyway
  before do
    allow(controller).to receive(:render).and_call_original
  end

  describe "get left panel" do
    before do
      # other setup
      get 'left_panel'
    end

    it 'should render correct template for lelf_panel' do
      # Sadly, render_template is primitive (no hash_including, no block with args, etc.)
      expect(subject).to render_template('system/_left_panel')
    end

    it 'should render with correct local value' do
      expect(controller).to have_received(:render) do |options|
        expect(options[:locals][:key_from_very_long_hash]).to eq('value_of_key_from_very_long_hash')
      end
    end
  end

```