简体   繁体   中英

How do I write a spec to verify the rendering of partials?

I'm using rr (the mocking framework) and rspec with ruby-on-rails. Also, I'm using the collection short hand for partial rendering. My question: How do I correctly fill out the the following view spec?

describe 'my_view' do
  before(:each) do
    assigns[:models] = Array.new(10, stub(Model))
  end

  it "should render the 'listing' partial for each model" do
    # help me write something that actually verifies this
  end
end

I've tried a few examples from the rspec book, rspec docs, and rr docs. Everything I try seems to leave me with runtime errors in the test - not failed assertions. Rather than show all the transformations I've tried, I figured all I'd need if someone showed me one that actually worked. I'd be good to go from there.

I would suggest asserting the presence of some HTML that the "listing" partial should generate. Otherwise, it sounds like you're trying to assert that Rails is technically calling render on the partial? That's the job of the Rails core tests to prove such functionality.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM