Skip to content

Commit

Permalink
Merge pull request #437 from cucumber/refactor/remove_web_steps
Browse files Browse the repository at this point in the history
Refactor: Remove web_steps.rb
  • Loading branch information
luke-hill authored Aug 27, 2019
2 parents 586d9eb + 63ba6b6 commit 03ea1d8
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 339 deletions.
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ require:
AllCops:
TargetRubyVersion: 2.3
Exclude:
# This file is something which we aren't advising people to use
# Probably need to consider deleting this fully at some point
- 'features/support/legacy_web_steps_support.rb'
# These are auto-generated from a load of features that we
# don't have direct control over
- 'tmp/**/*'
Expand Down
4 changes: 2 additions & 2 deletions features/annotations.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Feature: Annotations

I order to track my development progress
In order to track my development progress
As a developer
I should be able to list annotations in my features

Expand All @@ -16,5 +16,5 @@ Feature: Annotations
Then it should pass with:
"""
features/products.feature:
* [ 3] [TODO] When I go to the products page
* [3] [TODO] When I go to the products page
"""
36 changes: 28 additions & 8 deletions features/capybara_javascript_drivers.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ Feature: Capybara Javascript Drivers
Given I have created a new Rails app and installed cucumber-rails
And I force selenium to run Firefox in headless mode
When I run `bundle exec rails g scaffold appointment name:string when:datetime`
And I write to "features/step_definitions/date_time_steps.rb" with:
"""
When('I select {string} as the {string} date and time') do |datetime, selector|
select_datetime(datetime, from: selector)
end
"""

Scenario: Use a particular driver
When I write to "features/create_appointment.feature" with:
Expand All @@ -25,6 +19,28 @@ Feature: Capybara Javascript Drivers
Then I should see "Norway's constitution"
And I should see "2015-02-20 15:10:00 UTC"
"""
And I write to "features/create_appointment_steps.rb" with:
"""
Given('I am on the new appointment page') do
visit new_appointment_path
end
When('I fill in {string} for {string}') do |value, field|
fill_in(field, with: value)
end
When('I press {string}') do |button|
click_button(button)
end
Then('I should see {string}') do |text|
expect(page).to have_content(text)
end
When('I select {string} as the {string} date and time') do |datetime, selector|
select_datetime(datetime, from: selector)
end
"""
And I run `bundle exec rake db:migrate`
And I run `bundle exec rake cucumber`
Then the feature run should pass with:
Expand All @@ -40,7 +56,7 @@ Feature: Capybara Javascript Drivers
Feature: Create appointments
Scenario: Visit the Constitution on May 17
Given a random appointment
And I am viewing a random appointment
And I am viewing the appointment
Then I should see "Random appointment"
"""
And I write to "features/step_definitions/create_appointment_steps.rb" with:
Expand All @@ -49,9 +65,13 @@ Feature: Capybara Javascript Drivers
@appointment = Appointment.create!(name: 'Random appointment', when: DateTime.now)
end
Given('I am viewing a random appointment') do
Given('I am viewing the appointment') do
visit appointment_path(@appointment)
end
Then('I should see {string}') do |text|
expect(page).to have_content(text)
end
"""
And I run `bundle exec rake db:migrate`
And I run `bundle exec rake cucumber`
Expand Down
2 changes: 1 addition & 1 deletion features/database_cleaner.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Feature: DatabaseCleaner
Feature: Database Cleaner

Scenario: Create records in background
Given I have created a new Rails app and installed cucumber-rails
Expand Down
67 changes: 41 additions & 26 deletions features/emulate_javascript.feature
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
Feature: Emulate Javascript

Scenario: See a widget
Background:
Given I have created a new Rails app and installed cucumber-rails
And I force selenium to run Firefox in headless mode
When I run `rails generate scaffold widget name:string`
And I write to "features/widgets.feature" with:
"""
@javascript
Feature: Widget inventory
Scenario: View a widget
Given there is a widget named "wrench"
When I go to the widgets page
Then I should see "wrench"
"""
And I write to "features/step_definitions/widget_steps.rb" with:
"""
"""
Given('there is a widget named {string}') do |name|
FactoryBot.create(:widget, name: name)
end
When('I am on the widgets page') do
visit widgets_path
end
Then('I should see {string}') do |text|
expect(page).to have_content(text)
end
"""
And I write to "features/support/factories/widget.rb" with:
"""
Expand All @@ -27,6 +26,17 @@ Feature: Emulate Javascript
end
end
"""

Scenario: See a widget
When I write to "features/widgets.feature" with:
"""
@javascript
Feature: Widget inventory
Scenario: Delete a widget
Given there is a widget named "wrench"
And I am on the widgets page
Then I should see "wrench"
"""
And I run `bundle exec rake db:migrate`
And I run `bundle exec rake cucumber`
Then the feature run should pass with:
Expand All @@ -36,9 +46,7 @@ Feature: Emulate Javascript
"""

Scenario: Pass on the CSRF token
Given I have created a new Rails app and installed cucumber-rails
When I run `rails generate scaffold widget name:string`
And I run `sed -i -e 's/forgery_protection *= false/forgery_protection = true/' config/environments/test.rb`
When I run `sed -i -e 's/forgery_protection *= false/forgery_protection = true/' config/environments/test.rb`
And I run `rails generate controller session establish`
And I write to "app/controllers/session_controller.rb" with:
"""
Expand All @@ -63,26 +71,33 @@ Feature: Emulate Javascript
Feature: Widget inventory
Scenario: Delete a widget
Given there is a widget named "wrench"
When I go to the session establish page
And I go to the widgets page
And I am on the session establish page
And I am on the widgets page
Then I should see "wrench"
When I follow "Destroy"
Then I should not see "denied"
And I should be on the widgets page
And I should not see "wrench"
"""
And I write to "features/step_definitions/widget_steps.rb" with:
And I append to "features/step_definitions/widget_steps.rb" with:
# TODO: Remove the newline below (Required) once bug is fixed: https://github.com/cucumber/aruba/issues/662
"""
Given('there is a widget named {string}') do |name|
FactoryBot.create(:widget, name: name)
Given('I am on the session establish page') do
visit session_establish_path
end
"""
And I write to "features/support/factories/widget.rb" with:
"""
FactoryBot.define do
factory :widget do
name { 'testwidget' }
end
When('I follow {string}') do |link|
click_link(link)
end
Then('I should not see {string}') do |text|
expect(page).not_to have_content(text)
end
Then('I should be on the widgets page') do
current_path = URI.parse(current_url).path
expect(current_path).to eq(widgets_path)
end
"""
And I run `bundle exec rake db:migrate`
Expand Down
4 changes: 2 additions & 2 deletions features/install_cucumber_rails.feature
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Feature: Install Rails
In order to take over the world
Feature: Install Cucumber Rails

Cucumber-Rails should work on supported versions
of Ruby on Rails, with Capybara and DatabaseCleaner

Expand Down
1 change: 1 addition & 0 deletions features/no_database.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Feature: No Database

Allow Cucumber to work with a Rails app without a database

Scenario: No ActiveRecord and DatabaseCleaner
Expand Down
14 changes: 10 additions & 4 deletions features/raising_errors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ Feature: Raise Errors

Scenario: Raise error for undefined route
Given I have created a new Rails app with no database and installed cucumber-rails
When I write to "features/products.feature" with:
When I write to "features/home.feature" with:
"""
Feature: Products
Scenario: Test a Product
When I go to the products page
Feature: Tests
Scenario: Tests
When I go to the home page
"""
And I write to "features/home_steps.rb" with:
"""
When('I go to the home page') do
visit('/')
end
"""
And I run `bundle exec cucumber`
Then it should fail with:
Expand Down
1 change: 1 addition & 0 deletions features/rerun_profile.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Feature: Rerun profile

In order to concentrate on failing features
As a Rails developer working with Cucumber
I want to rerun only failing features
Expand Down
2 changes: 1 addition & 1 deletion features/rest_api.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Feature: REST API
get(path)
end
Then(/^the response should be JSON:$/) do |json|
Then('the response should be JSON:') do |json|
expect(JSON.parse(last_response.body)).to eq(JSON.parse(json))
end
"""
Expand Down
3 changes: 0 additions & 3 deletions features/step_definitions/cucumber_rails_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
Given('I have created a new Rails app and installed cucumber-rails, accidentally outside of the test group in my Gemfile') do
rails_new
install_cucumber_rails :not_in_test_group
create_web_steps
end

Given('I have created a new Rails app and installed cucumber-rails') do
rails_new
install_cucumber_rails
create_web_steps
end

Given('I have created a new Rails app with no database and installed cucumber-rails') do
rails_new args: '--skip-active-record'
install_cucumber_rails :no_database_cleaner, :no_factory_bot
overwrite_file('features/support/env.rb', "require 'cucumber/rails'\n")
create_web_steps
end

Given('I have a {string} ActiveRecord model object') do |name|
Expand Down
Loading

0 comments on commit 03ea1d8

Please sign in to comment.