Last active
August 29, 2015 14:09
-
-
Save avdgaag/6dc26d8fbba2cd4ce458 to your computer and use it in GitHub Desktop.
Page objects in Ruby for use with Capybara
This file contains 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 ProductForm | |
attr_reader :page, :form | |
def initialize(page) | |
@page = page | |
@form = page.find('form.new_product') | |
end | |
def title=(new_title) | |
form.fill_in 'product_title', with: new_title | |
end | |
def save | |
form.click_button 'Create Product' | |
end | |
def has_validation_errors? | |
form.has_css?('.error') | |
end | |
end | |
RSpec.describe 'Creating a product' do | |
it 'shows validation errors when the name is too short' do | |
visit '/products/new' | |
product_form = ProductForm.new(page) | |
product_form.title = 'x' | |
product_form.save | |
expect(product_form).to have_validation_errors | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment