New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add page object example #13

Merged
merged 1 commit into from May 31, 2017
Jump to file or symbol
Failed to load files and symbols.
+111 −26
Diff settings

Always

Just for now

@@ -0,0 +1,23 @@
require 'feature_helper'
module Components
class BlogForm
include RSpec::Matchers
include Capybara::DSL
def create(title:, text:)
within blog_form do
fill_in 'blog_title', with: title
fill_in 'blog_text', with: text
click_on 'Save Blog'
end
end
private
def blog_form
find('.blog--new')
end
end
end
@@ -1,36 +1,32 @@
require 'feature_helper'
require_relative '../pages/new_blog'
require_relative '../pages/view_blog'
feature 'Form Examples', type: :feature do
scenario 'Successfully creating a new blog' do
visit '/'
click_on 'Form Examples'
expect(page).to have_content('Create Blog')
feature 'Blog management', type: :feature do
let(:new_blog_page) { ::Pages::NewBlog.new }
let(:view_blog_page) { ::Pages::ViewBlog.new }
fill_in 'blog_title', with: 'My Blog Title'
fill_in 'blog_text', with: 'My new blog text'
before :each do
new_blog_page.visit_location
end
click_on 'Save Blog'
expect(page).to have_selector('.blog--show')
scenario 'Successfully creating a new blog' do
new_blog_page.create title: 'My Blog Title',
text: 'My new blog text'
expect(page).to have_content('My Blog Title')
expect(page).to have_content('My new blog text')
expect(view_blog_page).to have_loaded
expect(view_blog_page).to have_blog title: 'My Blog Title',
text: 'My new blog text'
end
scenario 'Entering no data' do
visit '/'
click_on 'Form Examples'
expect(page).to have_content('Create Blog')
click_on 'Save Blog'
expect(page).to have_content('4 errors stopped this form being submitted')
expect(page).to have_content("Title can't be blank")
expect(page).to have_content("Text can't be blank")
expect(page).to have_content('Title is too short')
expect(page).to have_content('Text is too short')
new_blog_page.create title: '',
text: ''
expect(view_blog_page).to_not have_loaded
expect(new_blog_page).to have_errors "Title can't be blank",
"Text can't be blank",
"Title is too short",
"Text is too short"
end
end
Copy path View file
@@ -0,0 +1,41 @@
require 'feature_helper'
require_relative '../components/blog_form'
module Pages
class NewBlog
include RSpec::Matchers
include Capybara::DSL
def visit_location
visit '/blogs/new'
expect(self).to have_loaded
end
def has_loaded?
self.has_selector? 'h1', text: 'Create Blog'
end
def create(title:, text:)
blog_form.new.create title: title,
text: text
end
def has_errors?(*errors)
expect(self).to have_content("#{errors.count} errors stopped this form being submitted")
errors.each do |error|
expect(self).to have_error error
end
end
def has_error?(error)
has_selector? 'ul li', text: error
end
private
def blog_form
::Components::BlogForm
end
end
end
Copy path View file
@@ -0,0 +1,25 @@
require 'feature_helper'
module Pages
class ViewBlog
include RSpec::Matchers
include Capybara::DSL
def has_loaded?
self.has_selector? show_blog
end
def has_blog?(title:, text:)
within show_blog do
expect(page).to have_content title
expect(page).to have_content text
end
end
private
def show_blog
'.blog--show'
end
end
end
ProTip! Use n and p to navigate between commits in a pull request.