Last active
December 23, 2015 21:08
-
-
Save compactcode/6693884 to your computer and use it in GitHub Desktop.
RSpec features with page models.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Page | |
include Capybara::DSL | |
def initialize(&block) | |
validate_title | |
yield self | |
end | |
private | |
def validate_title | |
title.should =~ expected_title | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Public | |
class SignInPage < Page | |
def expected_title | |
/sign in/i | |
end | |
def email=(value) | |
fill_in('Email', :with => value) | |
end | |
def password=(value) | |
fill_in('Password', :with => value) | |
end | |
def submit | |
click_button('Sign In') | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
feature 'sign in' do | |
include_context 'a user named shanon' | |
include_examples 'a user named shanon has signed up' | |
scenario 'gives shanon continued access to his private dashboard' do | |
visit(new_sign_in_path) | |
Public::SignInPage.new do |page| | |
page.email = shanons_email | |
page.password = shanons_password | |
page.submit | |
end | |
Users::DashboardPage.new do |page| | |
page.user_email.should == shanons_email | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment