Skip to content

Instantly share code, notes, and snippets.

@compactcode
Last active December 23, 2015 21:08
Show Gist options
  • Save compactcode/6693884 to your computer and use it in GitHub Desktop.
Save compactcode/6693884 to your computer and use it in GitHub Desktop.
RSpec features with page models.
class Page
include Capybara::DSL
def initialize(&block)
validate_title
yield self
end
private
def validate_title
title.should =~ expected_title
end
end
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
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