ruby on rails - How to test partial with Capybara? -
in normal view spec file can test view capybara.
require 'spec_helper' describe 'site/login' subject { page } before { visit login_path } { should have_selector('#login form') } end
with rspec can test parital.
require 'spec_helper' describe 'site/sidebar' "displays login form" render :partial => "site/sidebar" expect(rendered).to match /form/ end end
also capybara can test view like
require 'spec_helper' describe 'site/sidebar' let!(:rendered) { render :partial => "site/sidebar" } let(:page) { capybara::node::simple.new(rendered) } { page.should have_selector('form') } end
last 1 seems working feels kinda hacky. there method exists in capybara such thing visit_partial
? thought can find similar in capybara::driver::base
couldn't find.
your hacky method looks fine me. if had lot of partials use shared context:
shared_context "rendered partial" let!(:rendered) { render :partial => partial } let(:page) { capybara::node::simple.new(rendered) } subject { page } end describe "my partial" let(:partial) { "site/sidebar" } include_context "rendered partial" { should have_selector('form') } end
Comments
Post a Comment