Skip to content

Instantly share code, notes, and snippets.

@avdgaag
Last active August 29, 2015 14:09
Show Gist options
  • Save avdgaag/6dc26d8fbba2cd4ce458 to your computer and use it in GitHub Desktop.
Save avdgaag/6dc26d8fbba2cd4ce458 to your computer and use it in GitHub Desktop.
Page objects in Ruby for use with Capybara
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