howitzer 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.gitignore +3 -1
- data/.ruby-gemset +1 -0
- data/.travis.yml +4 -1
- data/.yardopts +5 -0
- data/CHANGELOG.md +23 -1
- data/CONTRIBUTING.md +14 -0
- data/GETTING_STARTED.md +283 -183
- data/Gemfile +3 -2
- data/LICENSE +1 -1
- data/README.md +93 -39
- data/Rakefile +4 -0
- data/bin/howitzer +34 -5
- data/features/cli_help.feature +3 -2
- data/features/cli_new.feature +1 -1
- data/features/cli_unknown.feature +1 -1
- data/features/cli_update.feature +84 -0
- data/features/step_definitions/common_steps.rb +9 -1
- data/generators/base_generator.rb +30 -15
- data/generators/config/config_generator.rb +7 -7
- data/generators/config/templates/custom.yml +1 -0
- data/generators/config/templates/default.yml +35 -5
- data/generators/cucumber/templates/env.rb +2 -2
- data/generators/cucumber/templates/transformers.rb +3 -1
- data/generators/root/templates/Gemfile +5 -3
- data/generators/root/templates/Rakefile +2 -0
- data/generators/rspec/templates/example_spec.rb +3 -3
- data/generators/rspec/templates/spec_helper.rb +6 -7
- data/howitzer.gemspec +15 -15
- data/lib/howitzer/capybara/settings.rb +125 -49
- data/lib/howitzer/helpers.rb +161 -94
- data/lib/howitzer/mailgun/client.rb +1 -1
- data/lib/howitzer/tasks/framework.rake +3 -0
- data/lib/howitzer/utils.rb +1 -1
- data/lib/howitzer/utils/locator_store.rb +1 -1
- data/lib/howitzer/utils/log.rb +1 -1
- data/lib/howitzer/utils/page_validator.rb +1 -1
- data/lib/howitzer/version.rb +1 -1
- data/lib/howitzer/web_page.rb +11 -11
- data/spec/spec_helper.rb +25 -22
- data/spec/support/generator_helper.rb +8 -1
- data/spec/unit/generators/base_generator_spec.rb +242 -0
- data/spec/unit/generators/config_generator_spec.rb +34 -0
- data/spec/unit/generators/cucumber_generator_spec.rb +45 -0
- data/spec/unit/generators/emails_generator_spec.rb +31 -0
- data/spec/unit/generators/pages_generator_spec.rb +33 -0
- data/spec/unit/generators/root_generator_spec.rb +35 -0
- data/spec/unit/generators/rspec_generator_spec.rb +36 -0
- data/spec/unit/generators/tasks_generator_spec.rb +31 -0
- data/spec/unit/lib/capybara/dsl_ex_spec.rb +11 -11
- data/spec/unit/lib/capybara/settings_spec.rb +336 -58
- data/spec/unit/lib/email_spec.rb +17 -17
- data/spec/unit/lib/helpers_spec.rb +699 -315
- data/spec/unit/lib/mailgun/client_spec.rb +9 -9
- data/spec/unit/lib/mailgun/connector_spec.rb +20 -20
- data/spec/unit/lib/mailgun/response_spec.rb +9 -9
- data/spec/unit/lib/settings_spec.rb +6 -6
- data/spec/unit/lib/utils/data_generator/data_storage_spec.rb +31 -31
- data/spec/unit/lib/utils/data_generator/gen_spec.rb +20 -20
- data/spec/unit/lib/utils/locator_store_spec.rb +39 -39
- data/spec/unit/lib/utils/log_spec.rb +42 -42
- data/spec/unit/lib/utils/page_validator_spec.rb +69 -70
- data/spec/unit/lib/web_page_spec.rb +91 -69
- data/spec/unit/version_spec.rb +3 -3
- metadata +100 -78
- data/spec/unit/generators/generators_spec.rb +0 -175
data/Gemfile
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,47 +1,53 @@
|
|
1
1
|
# Howitzer
|
2
|
+
|
3
|
+
[![Join the chat at https://gitter.im/strongqa/howitzer](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/strongqa/howitzer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
2
4
|
[![Gem Version](http://img.shields.io/gem/v/howitzer.svg)][gem]
|
3
5
|
[![Build Status](https://travis-ci.org/strongqa/howitzer.svg?branch=master)][travis]
|
4
|
-
[![Dependency Status](https://gemnasium.com/
|
6
|
+
[![Dependency Status](https://gemnasium.com/strongqa/howitzer.svg)][gemnasium]
|
5
7
|
[![Code Climate](https://codeclimate.com/github/romikoops/howitzer.png)][codeclimate]
|
8
|
+
[![Coverage Status](https://coveralls.io/repos/strongqa/howitzer/badge.png?branch=master)][coveralls]
|
6
9
|
[![License](http://img.shields.io/badge/license-MIT-blue.svg)][license]
|
7
10
|
|
8
11
|
[gem]: https://rubygems.org/gems/howitzer
|
9
12
|
[travis]: https://travis-ci.org/strongqa/howitzer
|
10
|
-
[gemnasium]: https://gemnasium.com/
|
13
|
+
[gemnasium]: https://gemnasium.com/strongqa/howitzer
|
11
14
|
[codeclimate]: https://codeclimate.com/github/romikoops/howitzer
|
15
|
+
[coveralls]: https://coveralls.io/r/strongqa/howitzer?branch=master
|
12
16
|
[license]: https://github.com/strongqa/howitzer/blob/master/LICENSE
|
13
17
|
|
14
|
-
Howitzer is Ruby
|
18
|
+
Howitzer is a Ruby-based framework for acceptance testing.
|
19
|
+
|
20
|
+
It was originally developed for testing web applications, but you can also use it for API testing and web service testing.
|
15
21
|
|
16
|
-
|
17
|
-
The framework uses modern patterns, techniques and tools in automated testing area. For details, please see [Test Framework Design](https://github.com/strongqa/howitzer/wiki/Test-Framework-Design).
|
22
|
+
The framework was built with modern patterns, techniques, and tools in automated testing. For details, please see [Test Framework Design](https://github.com/strongqa/howitzer/wiki/Test-Framework-Design).
|
18
23
|
|
19
|
-
## Key
|
24
|
+
## Key Benefits
|
20
25
|
- Independent of test web application, its technologies and lanquage.
|
21
|
-
-
|
22
|
-
- Flexible test framework
|
23
|
-
-
|
24
|
-
-
|
25
|
-
- Easy
|
26
|
+
- Fast installation of the complete testing infrastructure (takes less than 5 minutes).
|
27
|
+
- Flexible configuration of the test framework.
|
28
|
+
- Possibility to choose between Cucumber or RSpec BDD tool.
|
29
|
+
- Integration with SauceLabs, Testingbot, BrowserStack and MailGun web services.
|
30
|
+
- Easy tests support.
|
26
31
|
- Ability to execute tests against to both browserless driver and actual browsers with no changes in your tests.
|
27
|
-
-
|
32
|
+
- Searches for broken links.
|
28
33
|
|
29
34
|
|
30
35
|
## Documentation
|
31
|
-
|
36
|
+
Refer to the [GETTING STARTED](http://rubydoc.info/gems/howitzer/file/GETTING_STARTED.md) document to start working with *Howitzer*.
|
32
37
|
|
33
|
-
|
38
|
+
You can also find the Rdoc documentation on [Rubygems](https://rubygems.org/gems/howitzer).
|
34
39
|
|
35
|
-
## Related
|
36
|
-
* [Howitzer Example](https://github.com/strongqa/howitzer_example)
|
37
|
-
* [Howitzer Stat](https://github.com/strongqa/howitzer_stat)
|
40
|
+
## Related Products
|
41
|
+
* [Howitzer Example](https://github.com/strongqa/howitzer_example) – an example of Howitzer based project for demo web application.
|
42
|
+
* [Howitzer Stat](https://github.com/strongqa/howitzer_stat) – is the extension to Howitzer product. It is used for automated tests coverage visualization of web pages.
|
38
43
|
|
39
44
|
## Requirements
|
40
45
|
* Supported OS: Mac OS X, Linux, Windows
|
41
|
-
* Ruby 1.9.3+
|
42
|
-
* [DevKit](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit#installation-instructions)(For **Windows** only)
|
46
|
+
* [Ruby](https://www.ruby-lang.org/en/downloads/) 1.9.3+
|
47
|
+
* [DevKit](https://github.com/oneclick/rubyinstaller/wiki/Development-Kit#installation-instructions) (For **Windows** only)
|
43
48
|
* [PhantomJS](http://phantomjs.org/download.html)
|
44
49
|
* [ChromeDriver](https://code.google.com/p/selenium/wiki/ChromeDriver)
|
50
|
+
* [QT](https://github.com/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit) (For **webkit** driver only)
|
45
51
|
|
46
52
|
## Setup
|
47
53
|
To install, type
|
@@ -51,7 +57,7 @@ gem install howitzer
|
|
51
57
|
```
|
52
58
|
|
53
59
|
## Usage
|
54
|
-
|
60
|
+
Browse to a desired directory where a new project will be created.
|
55
61
|
|
56
62
|
To deploy the framework with Cucumber, type:
|
57
63
|
|
@@ -59,7 +65,7 @@ To deploy the framework with Cucumber, type:
|
|
59
65
|
howitzer new <PROJECT NAME> --cucumber
|
60
66
|
```
|
61
67
|
|
62
|
-
|
68
|
+
The following folders and files will be generated:
|
63
69
|
```
|
64
70
|
config/
|
65
71
|
cucumber.yml
|
@@ -90,45 +96,93 @@ With Rspec:
|
|
90
96
|
howitzer new <PROJECT NAME> --rspec
|
91
97
|
```
|
92
98
|
|
93
|
-
With both
|
99
|
+
With both Cucumber and Rspec:
|
94
100
|
|
95
101
|
```bash
|
96
102
|
howitzer new <PROJECT NAME> --cucumber --rspec
|
97
103
|
```
|
98
104
|
|
99
|
-
|
100
|
-
|
105
|
+
**Configuration**
|
106
|
+
|
107
|
+
Learn and specify correct default settings in the `config/default.yml` file. For more details, please refer to the original [sexy_settings](https://github.com/romikoops/sexy_settings) gem.
|
101
108
|
|
102
|
-
## Test
|
109
|
+
## Test Implementation Workflow
|
103
110
|
|
104
|
-
- Prepare
|
105
|
-
- Implement appropriate pages in `pages` folder. For details,
|
111
|
+
- Prepare features and scenarios
|
112
|
+
- Implement appropriate pages in the `pages` folder. For details, refer to [Page Object Pattern](https://github.com/strongqa/howitzer/wiki/PageObject-pattern).
|
106
113
|
- Implement emails in `emails` folder.
|
107
114
|
- Implement scenarios:
|
108
|
-
* Cucumber:
|
115
|
+
* For Cucumber:
|
109
116
|
1. Read and learn [Cucumber Best Practices](https://github.com/strongqa/howitzer/wiki/Cucumber-Best-Practices)
|
110
|
-
2. Implement step definitions in `features/step_definitions/common_steps.rb` file.
|
111
|
-
* Rspec: Use [DSL](https://github.com/jnicklas/capybara/blob/master/lib/capybara/rspec/features.rb) provided by Capybara
|
117
|
+
2. Implement step definitions in the `features/step_definitions/common_steps.rb` file.
|
118
|
+
* For Rspec: Use [DSL](https://github.com/jnicklas/capybara/blob/master/lib/capybara/rspec/features.rb) provided by Capybara to create descriptive acceptance tests.
|
112
119
|
- Debug feature against to desired driver.
|
113
120
|
- Enjoy it!
|
114
121
|
|
115
|
-
## Rake
|
122
|
+
## Rake Tasks
|
116
123
|
|
117
|
-
You can list all available tasks
|
124
|
+
You can get a list of all available tasks by typing the following command:
|
118
125
|
|
119
126
|
```bash
|
120
127
|
rake -T
|
128
|
+
|
129
|
+
```
|
130
|
+
|
131
|
+
## Upgrading Howitzer
|
132
|
+
Before attempting to upgrade an existing project, you should be sure you have a good reason to upgrade. You need to balance several factors: the need for new features, the increasing difficulty of finding support for old code, and your available time and skills, to name a few.
|
133
|
+
|
134
|
+
From version _v1.1.0_ howitzer provides **howitzer update** command. After updating the Howitzer version in the Gemfile, run this rake task. This will help you with the creation of new files and changes of old files in an interactive session.
|
135
|
+
|
136
|
+
```
|
137
|
+
$ howitzer update
|
138
|
+
* Config files generation ...
|
139
|
+
Identical 'config/custom.yml' file
|
140
|
+
Added 'config/default.yml' file
|
141
|
+
* Root files generation ...
|
142
|
+
Added '.gitignore' file
|
143
|
+
Conflict with 'Gemfile' file
|
144
|
+
Overwrite 'Gemfile' file? [Yn]:Y
|
145
|
+
Forced 'Gemfile' file
|
146
|
+
Identical 'Rakefile' file
|
147
|
+
Conflict with 'boot.rb' file
|
148
|
+
Overwrite 'boot.rb' file? [Yn]:n
|
149
|
+
Skipped 'boot.rb' file
|
150
|
+
|
151
|
+
...
|
121
152
|
```
|
153
|
+
Don't forget to review the difference, to see if there were any unexpected changes and merge them. It is easy if your project is under revision control systems like _Git_.
|
122
154
|
|
123
|
-
##
|
155
|
+
## Additional Information
|
124
156
|
* [Rubygems](https://rubygems.org/gems/howitzer)
|
125
157
|
* [Mailing list](https://groups.google.com/forum/#!forum/howitzer_ruby)
|
126
158
|
* [Issues](https://github.com/strongqa/howitzer/issues)
|
159
|
+
* [Developer chat](https://gitter.im/strongqa/howitzer)
|
160
|
+
|
161
|
+
Contributing
|
162
|
+
------------
|
163
|
+
|
164
|
+
Please see [CONTRIBUTING.md](https://github.com/strongqa/howitzer/blob/master/CONTRIBUTING.md).
|
165
|
+
|
166
|
+
howitzer was originally designed by Roman Parashchenko and is now maintained by StrongQA team. You can find list of contributors here [open source
|
167
|
+
community](https://github.com/strongqa/howitzer/graphs/contributors).
|
168
|
+
|
169
|
+
License
|
170
|
+
-------
|
171
|
+
|
172
|
+
howitzer is Copyright © 2012-2015 Roman Parashchenko and StrongQA. It is free
|
173
|
+
software, and may be redistributed under the terms specified in the
|
174
|
+
[LICENSE](/LICENSE) file.
|
175
|
+
|
176
|
+
About StrongQA
|
177
|
+
----------------
|
178
|
+
|
179
|
+
![StrongQA](http://strongqa.com/head_logo_big.png)
|
180
|
+
|
181
|
+
howitzer is maintained and funded by StrongQA, Ltd.
|
182
|
+
The names and logos for StrongQA are trademarks of StrongQA, Ltd.
|
127
183
|
|
128
|
-
|
184
|
+
We love open source software!
|
185
|
+
See [our other projects][testing_solutions] or [hire us][hire] to consult and develop testing solutions.
|
129
186
|
|
130
|
-
|
131
|
-
|
132
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
133
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
134
|
-
5. Create new Pull Request
|
187
|
+
[testing_solutions]: http://strongqa.com/testing_solutions/?utm_source=github
|
188
|
+
[hire]: https://strongqa.com?utm_source=github
|
data/Rakefile
CHANGED
@@ -3,6 +3,7 @@ require "bundler"
|
|
3
3
|
Bundler.setup
|
4
4
|
|
5
5
|
require 'rake'
|
6
|
+
require 'yard'
|
6
7
|
require 'rspec/core/rake_task'
|
7
8
|
require 'cucumber/rake/task'
|
8
9
|
Bundler::GemHelper.install_tasks
|
@@ -15,4 +16,7 @@ end
|
|
15
16
|
desc "All tests"
|
16
17
|
task(all_tests: [:spec, :cucumber]) {}
|
17
18
|
|
19
|
+
YARD::Rake::YardocTask.new do |t|
|
20
|
+
end
|
21
|
+
|
18
22
|
task :default => :all_tests
|
data/bin/howitzer
CHANGED
@@ -21,7 +21,7 @@ module HowitzerCli
|
|
21
21
|
c.action do |global_options, options, args|
|
22
22
|
if args.size > 0
|
23
23
|
validate_options(options)
|
24
|
-
|
24
|
+
load_generators
|
25
25
|
path_to_dir = File.join(Dir.pwd, args.first)
|
26
26
|
puts " * New project directory creation ..."
|
27
27
|
Dir.mkdir(path_to_dir)
|
@@ -41,10 +41,19 @@ module HowitzerCli
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
|
44
|
+
desc 'Upgrade existing project'
|
45
|
+
command :update do |c|
|
46
|
+
c.action do
|
47
|
+
check_project_presence
|
48
|
+
load_generators
|
49
|
+
Howitzer::ConfigGenerator.new
|
50
|
+
Howitzer::RootGenerator.new
|
51
|
+
Howitzer::CucumberGenerator.new if cucumber_integrated?
|
52
|
+
Howitzer::RspecGenerator.new if rspec_integrated?
|
53
|
+
end
|
46
54
|
end
|
47
55
|
|
56
|
+
#helpers
|
48
57
|
class << self
|
49
58
|
private
|
50
59
|
def validate_options(options)
|
@@ -52,9 +61,29 @@ module HowitzerCli
|
|
52
61
|
exit_now!("Provide --cucumber and/or --rspec option", 64)
|
53
62
|
end
|
54
63
|
end
|
64
|
+
|
65
|
+
def check_project_presence
|
66
|
+
exit_now!('Current directory is not Howitzer project', 126) unless howitzer_project?
|
67
|
+
end
|
68
|
+
|
69
|
+
def howitzer_project?
|
70
|
+
Dir.exists?('pages') && Dir.exists?('config') && File.exists?('boot.rb')
|
71
|
+
end
|
72
|
+
|
73
|
+
def load_generators
|
74
|
+
Dir[File.join(File.dirname(__FILE__), '..', 'generators', '**', '*_generator.rb')].each{ |f| require File.expand_path(f) }
|
75
|
+
end
|
76
|
+
|
77
|
+
def cucumber_integrated?
|
78
|
+
Dir.exists?('features')
|
79
|
+
end
|
80
|
+
|
81
|
+
def rspec_integrated?
|
82
|
+
Dir.exists?('spec')
|
83
|
+
end
|
55
84
|
end
|
56
85
|
end
|
57
86
|
|
58
87
|
unless ENV['TEST_MODE']
|
59
|
-
HowitzerCli.
|
60
|
-
end
|
88
|
+
exit(HowitzerCli.run(ARGV))
|
89
|
+
end
|
data/features/cli_help.feature
CHANGED
@@ -18,8 +18,9 @@ Feature: Howitzer CLI Help
|
|
18
18
|
--version - Display the program version
|
19
19
|
|
20
20
|
COMMANDS
|
21
|
-
help
|
22
|
-
new
|
21
|
+
help - Shows a list of commands or help for one command
|
22
|
+
new - Generate new project
|
23
|
+
update - Upgrade existing project
|
23
24
|
|
24
25
|
"""
|
25
26
|
And the exit status should be 0
|
data/features/cli_new.feature
CHANGED
@@ -0,0 +1,84 @@
|
|
1
|
+
Feature: Howitzer CLI Update Existing Project
|
2
|
+
|
3
|
+
Scenario: Run with update command when project present
|
4
|
+
Given created old howitzer project
|
5
|
+
When I run `howitzer update` interactively
|
6
|
+
And I type "y"
|
7
|
+
And I type "n"
|
8
|
+
And I type "i"
|
9
|
+
Then the output should contain:
|
10
|
+
"""
|
11
|
+
* Config files generation ...
|
12
|
+
Identical 'config/custom.yml' file
|
13
|
+
Added 'config/default.yml' file
|
14
|
+
* Root files generation ...
|
15
|
+
Added '.gitignore' file
|
16
|
+
Conflict with 'Gemfile' file
|
17
|
+
Overwrite 'Gemfile' file? [Yn]: Forced 'Gemfile' file
|
18
|
+
Identical 'Rakefile' file
|
19
|
+
Conflict with 'boot.rb' file
|
20
|
+
Overwrite 'boot.rb' file? [Yn]: Skipped 'boot.rb' file
|
21
|
+
* Cucumber integration to the framework ...
|
22
|
+
Identical 'features/step_definitions/common_steps.rb' file
|
23
|
+
Identical 'features/support/env.rb' file
|
24
|
+
Identical 'features/support/transformers.rb' file
|
25
|
+
Identical 'features/example.feature' file
|
26
|
+
Identical 'tasks/cucumber.rake' file
|
27
|
+
Identical 'config/cucumber.yml' file
|
28
|
+
* RSpec integration to the framework ...
|
29
|
+
Identical 'spec/spec_helper.rb' file
|
30
|
+
Identical 'spec/example_spec.rb' file
|
31
|
+
Identical 'tasks/rspec.rake' file
|
32
|
+
"""
|
33
|
+
And the exit status should be 0
|
34
|
+
When I run `howitzer update` interactively
|
35
|
+
And I type "y"
|
36
|
+
Then the output should contain:
|
37
|
+
"""
|
38
|
+
* Config files generation ...
|
39
|
+
Identical 'config/custom.yml' file
|
40
|
+
Identical 'config/default.yml' file
|
41
|
+
* Root files generation ...
|
42
|
+
Identical '.gitignore' file
|
43
|
+
Identical 'Gemfile' file
|
44
|
+
Identical 'Rakefile' file
|
45
|
+
Conflict with 'boot.rb' file
|
46
|
+
Overwrite 'boot.rb' file? [Yn]: Forced 'boot.rb' file
|
47
|
+
* Cucumber integration to the framework ...
|
48
|
+
Identical 'features/step_definitions/common_steps.rb' file
|
49
|
+
Identical 'features/support/env.rb' file
|
50
|
+
Identical 'features/support/transformers.rb' file
|
51
|
+
Identical 'features/example.feature' file
|
52
|
+
Identical 'tasks/cucumber.rake' file
|
53
|
+
Identical 'config/cucumber.yml' file
|
54
|
+
* RSpec integration to the framework ...
|
55
|
+
Identical 'spec/spec_helper.rb' file
|
56
|
+
Identical 'spec/example_spec.rb' file
|
57
|
+
Identical 'tasks/rspec.rake' file
|
58
|
+
"""
|
59
|
+
And the exit status should be 0
|
60
|
+
|
61
|
+
Scenario: Run with update command when project missing
|
62
|
+
When I run `howitzer update`
|
63
|
+
Then the output should contain:
|
64
|
+
"""
|
65
|
+
error: Current directory is not Howitzer project
|
66
|
+
"""
|
67
|
+
And the exit status should be 126
|
68
|
+
|
69
|
+
Scenario Outline: Run with update command with help option
|
70
|
+
When I run `howitzer update <option>`
|
71
|
+
Then the output should contain exactly:
|
72
|
+
"""
|
73
|
+
NAME
|
74
|
+
update - Upgrade existing project
|
75
|
+
|
76
|
+
SYNOPSIS
|
77
|
+
howitzer [global options] update
|
78
|
+
|
79
|
+
"""
|
80
|
+
And the exit status should be 0
|
81
|
+
Examples:
|
82
|
+
| option |
|
83
|
+
| --help |
|
84
|
+
| -h |
|
@@ -1 +1,9 @@
|
|
1
|
-
|
1
|
+
Given /^created old howitzer project$/ do
|
2
|
+
clean_current_dir
|
3
|
+
run_simple 'howitzer new test_automation --rspec --cucumber'
|
4
|
+
FileUtils.move(Dir.glob("#{Dir.pwd}/#{current_dir}/test_automation/*"), File.join(Dir.pwd, current_dir))
|
5
|
+
FileUtils.remove_dir File.join(current_dir, 'test_automation'), true
|
6
|
+
overwrite_file('boot.rb', "Dir.chdir(File.join(File.dirname(__FILE__), '.'))")
|
7
|
+
overwrite_file('Gemfile', "Hello")
|
8
|
+
remove_file 'config/default.yml'
|
9
|
+
end
|
@@ -2,12 +2,8 @@ require 'fileutils'
|
|
2
2
|
|
3
3
|
module Howitzer
|
4
4
|
class BaseGenerator
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.destination=(destination)
|
10
|
-
@destination = destination
|
5
|
+
class << self
|
6
|
+
attr_accessor :logger, :destination
|
11
7
|
end
|
12
8
|
|
13
9
|
def initialize
|
@@ -16,11 +12,9 @@ module Howitzer
|
|
16
12
|
case type
|
17
13
|
when :files
|
18
14
|
copy_files(list)
|
19
|
-
#:nocov:
|
20
15
|
when :templates
|
21
16
|
copy_templates(list)
|
22
17
|
else nil
|
23
|
-
#:nocov:
|
24
18
|
end
|
25
19
|
end
|
26
20
|
end
|
@@ -31,11 +25,11 @@ module Howitzer
|
|
31
25
|
def banner; end
|
32
26
|
|
33
27
|
def logger
|
34
|
-
BaseGenerator.
|
28
|
+
BaseGenerator.logger || $stdout
|
35
29
|
end
|
36
30
|
|
37
31
|
def destination
|
38
|
-
BaseGenerator.
|
32
|
+
BaseGenerator.destination || Dir.pwd
|
39
33
|
end
|
40
34
|
|
41
35
|
def copy_files(list)
|
@@ -45,7 +39,7 @@ module Howitzer
|
|
45
39
|
if File.exists?(source_file)
|
46
40
|
copy_with_path(data)
|
47
41
|
else
|
48
|
-
|
42
|
+
puts_error("File '#{source_file}' was not found.")
|
49
43
|
end
|
50
44
|
end
|
51
45
|
end
|
@@ -59,10 +53,14 @@ module Howitzer
|
|
59
53
|
end
|
60
54
|
|
61
55
|
def print_info(data)
|
56
|
+
logger.print " #{data}"
|
57
|
+
end
|
58
|
+
|
59
|
+
def puts_info(data)
|
62
60
|
logger.puts " #{data}"
|
63
61
|
end
|
64
62
|
|
65
|
-
def
|
63
|
+
def puts_error(data)
|
66
64
|
logger.puts " ERROR: #{data}"
|
67
65
|
end
|
68
66
|
|
@@ -80,10 +78,27 @@ module Howitzer
|
|
80
78
|
src = source_path(data[:source])
|
81
79
|
dst = dest_path(data[:destination])
|
82
80
|
FileUtils.mkdir_p(File.dirname(dst))
|
83
|
-
|
84
|
-
|
81
|
+
if File.exists?(dst)
|
82
|
+
if FileUtils.identical?(src, dst)
|
83
|
+
puts_info("Identical '#{data[:destination]}' file")
|
84
|
+
else
|
85
|
+
puts_info("Conflict with '#{data[:destination]}' file")
|
86
|
+
print_info(" Overwrite '#{data[:destination]}' file? [Yn]:")
|
87
|
+
case gets.strip.downcase
|
88
|
+
when 'y'
|
89
|
+
FileUtils.cp(src, dst)
|
90
|
+
puts_info(" Forced '#{data[:destination]}' file")
|
91
|
+
when 'n' then nil
|
92
|
+
puts_info(" Skipped '#{data[:destination]}' file")
|
93
|
+
else nil
|
94
|
+
end
|
95
|
+
end
|
96
|
+
else
|
97
|
+
FileUtils.cp(src, dst)
|
98
|
+
puts_info("Added '#{data[:destination]}' file")
|
99
|
+
end
|
85
100
|
rescue => e
|
86
|
-
|
101
|
+
puts_error("Impossible to create '#{data[:destination]}' file. Reason: #{e.message}")
|
87
102
|
end
|
88
103
|
end
|
89
104
|
end
|