現在、アプリケーションで何が起こっているのかを理解しようとして、いくつかの実際の問題が発生しています。サインアップに使用した方法(OAuthかどうか)に応じて、「プロファイルの編集」ページにさまざまなコンテンツを表示できるようにしています。
ユーザーモデルにOAuth属性を追加してテストするだけで、ブラウザーで手動でテストするときに、これが正しく機能するようになりました。
ただし、RSpecではこれを正しくテストできません。実際、ページで検索するように指示した要素に関係なく、それらは実際にそこにあると主張します。
describe "edit user" do
let(:user) { FactoryGirl.create(:user) }
before { sign_in user }
describe "correct edit account options shown to normal users" do
before do
visit edit_user_registration_path(:user)
end
it { should have_selector('h2', text: 'Edit User') }
it { should have_selector('input', id: 'user_names')}
it { should have_selector('input', id: 'user_email', value: user.email) }
it { should have_selector('input', id: 'user_password') }
it { should have_selector('input', id: 'user_password_confirmation') }
it { should have_selector('input', id: 'user_current_password') }
it { should have_selector('input', type: 'submit') }
end
describe "correct edit account options shown to oauth users" do
before do
user.update_attributes!(:oauth => true)
visit edit_user_registration_path(:user)
end
it { should have_selector('h2', text: 'Edit User') }
it { should have_selector('input', id: 'user_names')}
it { should_not have_selector('input', id: 'user_email') }
it { should_not have_selector('input', id: 'users_password') }
it { should_not have_selector('input', id: 'users_password_confirmation') }
it { should_not have_selector('input', id: 'user_current_password') }
it { should have_selector('input', type: 'submit') }
end
end
私のRSpec統合テストの完全なコードはここにあります:https ://gist.github.com/2556055
これについてのどんな助けも心から感謝されるでしょう。