Skip to content

Instantly share code, notes, and snippets.

@gsluthra
Created January 10, 2014 15:11
Show Gist options
  • Save gsluthra/8356015 to your computer and use it in GitHub Desktop.
Save gsluthra/8356015 to your computer and use it in GitHub Desktop.
Capybara and RSpec Feature file that uses Page objects.
# Page Object
class CapsuleCreateForm
include Capybara::DSL
def submit_form(capsule={})
fill_in 'Title', :with => capsule[:title]
fill_in 'Description', :with => capsule[:description]
fill_in 'capsule_study_text', :with => capsule[:study_text]
fill_in 'capsule_assignment_instructions', :with => capsule[:assignment_instructions]
fill_in 'capsule_guidelines_for_evaluators', :with => capsule[:guidelines_for_evaluators]
click_button 'Save Capsule'
end
end
require 'spec_helper'
#Feature File
feature 'Capsules Feature' do
let(:capsuleHash) { attributes_for(:tdd_capsule) }
let(:capsuleForm) { CapsuleCreateForm.new }
let(:capsuleViewPage) { CapsuleViewPage.new }
scenario 'Add a new capsule and displays the capsule in view mode' do
visit '/capsules/new'
expect {
capsuleForm.submit_form(capsuleHash)
}.to change(Capsule, :count).by(1)
capsuleViewPage.validate_on_page
capsuleViewPage.validate_capsule_data(capsuleHash)
end
end
require 'spec_helper'
# Page Object
class CapsuleViewPage
include Capybara::DSL
include RSpec::Matchers
def validate_on_page
expect(page).to have_selector('#capsule-title-page')
expect(page).to have_link('Edit')
end
def validate_capsule_data (capsule={})
expect(page).to have_content capsule[:title]
expect(page).to have_content capsule[:description]
expect(page).to have_content capsule[:study_text]
expect(page).to have_content capsule[:assignment_instructions]
expect(page).to have_content capsule[:guidelines_for_evaluators]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment