Skip to content

Instantly share code, notes, and snippets.

@he9lin
Created October 17, 2014 17:45
Show Gist options
  • Save he9lin/edb3e2deeb0746d9f357 to your computer and use it in GitHub Desktop.
Save he9lin/edb3e2deeb0746d9f357 to your computer and use it in GitHub Desktop.
Interface steps
step "I visit the :page_path page" do |path|
path = send(path) unless path.is_a?(String)
visit path
end
step "I click :text" do |text|
click_on text
end
step "I click :text within the :page_element" do |text, element_css|
within element_css do
click_on text
end
end
step "I submit the :form_name form" do |form_data|
within form_data[0] do
click_button form_data[1]
end
end
step "I submit the :form_name form with:" do |form_data, table|
within form_data[0] do
table.rows_hash.each do |key, value|
fill_in key, with: value, exact: false
end
click_button form_data[1]
end
end
# Expectations
step "I should see :content" do |content|
expect(page).to have_content(content)
end
step "I should not see :content" do |content|
expect(page).not_to have_content(content)
end
step "I should see :content within the :page_element" do |content, element_css|
within element_css do
expect(page).to have_content(content)
end
end
step "I should not see :page_element" do |element_css|
expect(page).not_to have_css(element_css)
end
step "I should have received an email at :email_address" do |email_address|
last_email.should_not be_nil
last_email.destinations.should include(email_address)
end
step "I should be on the :page_path page" do |path|
path = send(path) unless path.is_a?(String)
expect(current_path).to eq(path)
end
@he9lin
Copy link
Author

he9lin commented Oct 17, 2014

Sample placeholder_steps.rb

placeholder :form_name do
  match(/new invitation/) { |form_name| [".x-new-invite", "Send an invitation"] }
end

placeholder :page_element do
  match(/main navbar/) { "#main-nav" }
end

placeholder :page_path do
  match(/admin invitations/) { :admins_invitations_path }
  match(/admin home/) { :admins_root_path }
  match(/admin sign in/) { '/admins/sign_in' }
  match(/dashboard/) { '/dashboard' }
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment