Skip to content
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

Scaffolding commands #94

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Select the ones you will like to work with.

```ruby
Commands:
raider generate # Provides access to all the generators commands
raider generate # Provides access to all the scaffolding commands
raider help [COMMAND] # Describe available commands or one specific command
raider new [PROJECT_NAME] # Creates a new framework based on settings picked
raider open_ai # Provides access to all the open ai commands
Expand All @@ -104,6 +104,29 @@ All the basic commands have their corresponding shortcut:
* u for utility
* v for version

### Scaffolding Commands
Ruby Raider also supports scaffolding:

* To create a new page object you do: ```raider g page [PAGE_NAME]```
* To create a new spec you do: ```raider g spec [SPEC_NAME]```
* To create a new feature you do: ```raider g feature [FEATURE_NAME]```
* To create a new steps definition you do: ```raider g steps [STEPS_NAME]```
* To create both a page/spec or a page/feature/steps you do: ```raider g scaffold [SCAFFOLD_NAME]```

It's possible to add the option --path or -p if you want to specify where to create your features, pages, helpers and
specs.

If you want to set the default path for the creation of your features, helpers and specs:

```ruby
raider u path [PATH_NAME] - -feature or -f
raider u path [PATH_NAME] - -spec or -s
raider u path [PATH_NAME] - -helper or -h
```

If you don't specify an option, path will assume you want to change the default path for pages.


### Appium Server Command
To initialise Appium server run this command:
```ruby
Expand Down
70 changes: 34 additions & 36 deletions lib/commands/scaffolding_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# :reek:FeatureEnvy { enabled: false }
# :reek:UtilityFunction { enabled: false }
# :reek:RepeatedConditional { enabled: false }
class ScaffoldingCommands < Thor
desc 'page [PAGE_NAME]', 'Creates a new page object'
option :path,
Expand All @@ -15,7 +16,9 @@ class ScaffoldingCommands < Thor
type: :boolean, required: false, desc: 'This will delete the selected page', aliases: '-d'

def page(name)
handle_scaffolding(name, 'page')
return delete_scaffolding(name, 'page') if options[:delete]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[reek] reported by reviewdog 🐶
RepeatedConditional: ScaffoldingCommands tests 'options[:delete]' at least 5 times [https://github.com/troessner/reek/blob/v6.3.0/docs/Repeated-Conditional.md]


generate_scaffolding(name, 'page', options[:path])
end

desc 'feature [NAME]', 'Creates a new feature'
Expand All @@ -27,7 +30,9 @@ def page(name)
required: false, desc: 'This will delete the selected feature', aliases: '-d'

def feature(name)
handle_scaffolding(name, 'feature')
return delete_scaffolding(name, 'feature') if options[:delete]

generate_scaffolding(name, 'feature', options[:path])
end

desc 'spec [SPEC_NAME]', 'Creates a new spec'
Expand All @@ -37,7 +42,9 @@ def feature(name)
type: :boolean, required: false, desc: 'This will delete the selected spec', aliases: '-d'

def spec(name)
handle_scaffolding(name, 'spec')
return delete_scaffolding(name, 'spec') if options[:delete]

generate_scaffolding(name, 'spec', options[:path])
end

desc 'helper [HELPER_NAME]', 'Creates a new helper'
Expand All @@ -47,7 +54,21 @@ def spec(name)
type: :boolean, required: false, desc: 'This will delete the selected helper', aliases: '-d'

def helper(name)
handle_scaffolding(name, 'helper')
return delete_scaffolding(name, 'helper') if options[:delete]

generate_scaffolding(name, 'helper', options[:path])
end

desc 'steps [STEPS_NAME]', 'Creates a new steps definition'
option :path,
type: :string, required: false, desc: 'The path where your steps will be created', aliases: '-p'
option :delete,
type: :boolean, required: false, desc: 'This will delete the selected steps', aliases: '-d'

def steps(name)
return delete_scaffolding(name, 'steps') if options[:delete]

generate_scaffolding(name, 'steps', options[:path])
end

desc 'scaffold [SCAFFOLD_NAME]', 'It generates everything needed to start automating'
Expand All @@ -57,46 +78,23 @@ def scaffold(name)
Scaffolding.new([name, load_config_path('spec')]).generate_spec
else
Scaffolding.new([name, load_config_path('feature')]).generate_feature
Scaffolding.new([name, load_config_path('steps')]).generate_steps
end
Scaffolding.new([name, load_config_path('page')]).generate_class
Scaffolding.new([name, load_config_path('page')]).generate_page
end

desc 'config', 'Creates configuration file'
option :delete,
type: :boolean, required: false, desc: 'This will delete the config file', aliases: '-d'

no_commands do
def load_config_path(type)
YAML.load_file('config/config.yml')["#{type}_path"] if Pathname.new('config/config.yml').exist?
end

def handle_scaffolding(name, type)
path = options[:path] || load_config_path(type)
scaffolding = Scaffolding.new([name, path])

if options[:delete]
case type
when 'page'
scaffolding.delete_class
when 'feature'
scaffolding.delete_feature
when 'spec'
scaffolding.delete_spec
when 'helper'
scaffolding.delete_helper
end
else
case type
when 'page'
scaffolding.generate_class
when 'feature'
scaffolding.generate_feature
when 'spec'
scaffolding.generate_spec
when 'helper'
scaffolding.generate_helper
end
end
def delete_scaffolding(name, type)
Scaffolding.new([name]).send("delete_#{type}")
end

def generate_scaffolding(name, type, path)
path ||= load_config_path(type)
Scaffolding.new([name, path]).send("generate_#{type}")
end
end
end
28 changes: 25 additions & 3 deletions lib/generators/templates/common/read_me.tt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Ruby Raider is a generator and scaffolding gem to make UI test automation easier
| Rspec and Watir | | Rspec and Appium for Android |
| | | Cucumber and Appium Cross-platform |
| | | Rspec and Appium Cross-platform |
| | | Cucumber and Sparkling Watir for IOS |
| | | Cucumber and Sparkling Watir for IOS |
| | | Rspec and Sparkling Watir for IOS |


Expand Down Expand Up @@ -86,7 +86,7 @@ Select the ones you will like to work with.

```ruby
Commands:
raider generate # Provides access to all the generators commands
raider generate # Provides access to all the scaffolding commands
raider help [COMMAND] # Describe available commands or one specific command
raider new [PROJECT_NAME] # Creates a new framework based on settings picked
raider open_ai # Provides access to all the open ai commands
Expand All @@ -102,6 +102,28 @@ All the basic commands have their corresponding shortcut:
* u for utility
* v for version

### Scaffolding Commands
Ruby Raider also supports scaffolding:

* To create a new page object you do: ```raider g page [PAGE_NAME]```
* To create a new spec you do: ```raider g spec [SPEC_NAME]```
* To create a new feature you do: ```raider g feature [FEATURE_NAME]```
* To create a new steps definition you do: ```raider g steps [STEPS_NAME]```
* To create both a page/spec or a page/feature/steps you do: ```raider g scaffold [SCAFFOLD_NAME]```

It's possible to add the option --path or -p if you want to specify where to create your features, pages, helpers and
specs.

If you want to set the default path for the creation of your features, helpers and specs:

```ruby
raider u path [PATH_NAME] - -feature or -f
raider u path [PATH_NAME] - -spec or -s
raider u path [PATH_NAME] - -helper or -h
```

If you don't specify an option, path will assume you want to change the default path for pages.


### Appium Server Command
To initialise Appium server run this command:
Expand All @@ -128,4 +150,4 @@ Options :
-pr, [--prompt = PROMPT] # This will create the selected steps based on your prompt using open ai
-i, [--input = INPUT] # It uses a file as input to create the steps

```
```
2 changes: 1 addition & 1 deletion lib/ruby_raider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def version

map 'v' => 'version'

desc 'generate', 'Provides access to all the generator commands'
desc 'generate', 'Provides access to all the scaffolding commands'
subcommand 'generate', ScaffoldingCommands
map 'g' => 'generate'

Expand Down
20 changes: 14 additions & 6 deletions lib/scaffolding/scaffolding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,51 @@ def self.source_root
"#{File.dirname(__FILE__)}/templates"
end

def generate_class
template('page_object.tt', default_path("page_objects/pages/#{name}_page.rb", '_page.rb'))
def generate_page
template('page_object.tt', default_path("page_objects/pages/#{name}.rb", '_page.rb'))
end

def generate_feature
template('feature.tt', default_path("features/#{name}.feature", '.feature'))
end

def generate_spec
template('spec.tt', default_path("spec/#{name}_spec.rb", '_spec.rb'))
template('spec.tt', default_path("spec/#{name}_page_spec.rb", '_spec.rb'))
end

def generate_helper
template('helper.tt', default_path("helpers/#{name}_helper.rb", '_helper.rb'))
end

def generate_steps
template('steps.tt', default_path("features/step_definitions/#{name}_steps.rb", '_steps.rb'))
end

def generate_config
template('../../generators/templates/common/config.tt',
default_path('config/config.yml', '.yml'))
end

def delete_class
remove_file(default_path("page_objects/pages/#{name}_page.rb", '_page.rb'))
def delete_page
remove_file(default_path("page_objects/pages/#{name}.rb", '_page.rb'))
end

def delete_feature
remove_file(default_path("features/#{name}.feature", '.feature'))
end

def delete_spec
remove_file(default_path("spec/#{name}_spec.rb", '_spec.rb'))
remove_file(default_path("spec/#{name}_page_spec.rb", '_spec.rb'))
end

def delete_helper
remove_file(default_path("helpers/#{name}_helper.rb", '_helper.rb'))
end

def delete_steps
remove_file(default_path("features/step_definitions/#{name}_steps.rb", '_steps.rb'))
end

def delete_config
remove_file(default_path('config/config.yml', '.yml'))
end
Expand Down
2 changes: 1 addition & 1 deletion lib/scaffolding/templates/feature.tt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Feature: <%= name %>
Feature: <%= name.capitalize %>

Scenario: Scenario name
Given I am
Expand Down
4 changes: 2 additions & 2 deletions lib/scaffolding/templates/page_object.tt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

require_relative '../abstract/abstract_page'
require_relative '../abstract/page'

class <%= name.split('_').map {|word| word.capitalize }.join + 'Page' %> < AbstractPage
class <%= name.split('_').map {|word| word.capitalize }.join %> < Page

# Actions

Expand Down
5 changes: 2 additions & 3 deletions lib/scaffolding/templates/spec.tt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require_relative 'base_spec'
require_relative '../page_objects/pages/<%= name %>_page'
require_relative '../page_objects/pages/<%= name %>'

describe <%= name.split('_').map {|word| word.capitalize }.join + 'Page' %> do
describe '<%= name.split('_').map {|word| word.capitalize }.join %>' do
end
12 changes: 12 additions & 0 deletions lib/scaffolding/templates/steps.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require_relative '../../page_objects/pages/<%= name %>'

Given ('') do
end

When ('') do
end

Then ('') do
end
18 changes: 14 additions & 4 deletions spec/integration/commands/scaffolding_commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@

it 'scaffolds for rspec creating a spec' do
scaffold.new.invoke(:scaffold, nil, %W[#{name}])
expect(Pathname.new("spec/#{name}_spec.rb")).to be_file
expect(Pathname.new("spec/#{name}_page_spec.rb")).to be_file
end

it 'scaffolds for rspec creating a page' do
scaffold.new.invoke(:scaffold, nil, %W[#{name}])
expect(Pathname.new("page_objects/pages/#{name}_page.rb")).to be_file
expect(Pathname.new("page_objects/pages/#{name}.rb")).to be_file
end

it 'deletes a spec' do
Expand All @@ -47,7 +47,7 @@

it 'creates a page' do
scaffold.new.invoke(:page, nil, %W[#{name}])
expect(Pathname.new("page_objects/pages/#{name}_page.rb")).to be_file
expect(Pathname.new("page_objects/pages/#{name}.rb")).to be_file
end

it 'creates a page with a path' do
Expand Down Expand Up @@ -77,14 +77,24 @@

it 'scaffolds for cucumber creating a page' do
scaffold.new.invoke(:scaffold, nil, %W[#{name}])
expect(Pathname.new("page_objects/pages/#{name}_page.rb")).to be_file
expect(Pathname.new("page_objects/pages/#{name}.rb")).to be_file
end

it 'scaffolds for cucumber creating a steps definition' do
scaffold.new.invoke(:scaffold, nil, %W[#{name}])
expect(Pathname.new("features/step_definitions/#{name}_steps.rb")).to be_file
end

it 'creates a helper' do
scaffold.new.invoke(:helper, nil, %W[#{name}])
expect(Pathname.new("helpers/#{name}_helper.rb")).to be_file
end

it 'creates a steps definition' do
scaffold.new.invoke(:steps, nil, %W[#{name}])
expect(Pathname.new("features/step_definitions/#{name}_steps.rb")).to be_file
end

it 'deletes a page' do
scaffold.new.invoke(:page, nil, %w[login --delete])
expect(Pathname.new('page_objects/pages/login_page.rb')).not_to be_file
Expand Down
Loading