Skip to content

Instantly share code, notes, and snippets.

@amalrik
Created March 2, 2019 13:47
Show Gist options
  • Save amalrik/b536de729cd01731b99efb1260dc094b to your computer and use it in GitHub Desktop.
Save amalrik/b536de729cd01731b99efb1260dc094b to your computer and use it in GitHub Desktop.
Using Page Object Pattern in rspec - POP final
class NewPostForm
include Capybara::DSL # Capybara
include FactoryBot::Syntax::Methods # FactoryBot
include Warden::Test::Helpers # Devise
include Rails.application.routes.url_helpers # Routes
def login(user)
login_as(user, :scope => :user)
self
end
def visit_page
visit new_post_path
self
end
def fill_in_with(params={})
within("#new_post") do
fill_in 'post_title', with: params.fetch(:post_title)
fill_in 'post_input_content', with: params.fetch(:post_input_content)
end
self
end
def submit
click_button 'Publish'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment