File tree Expand file tree Collapse file tree 3 files changed +50
-19
lines changed
features/step_definitions
metasploit/framework/database Expand file tree Collapse file tree 3 files changed +50
-19
lines changed Original file line number Diff line number Diff line change 1
- project_database_yaml_path = Rails . root . join ( 'config' , 'database.yml' ) . to_path
2
- backup_project_database_yaml_path = "#{ project_database_yaml_path } .cucumber.bak"
3
-
4
- Before do
5
- if File . exist? ( backup_project_database_yaml_path )
6
- File . delete ( backup_project_database_yaml_path )
7
- end
8
- end
1
+ require 'metasploit/framework/database/cucumber'
9
2
10
3
Given /^the project "database.yml" does not exist$/ do
11
- if File . exist? ( project_database_yaml_path )
12
- File . rename ( project_database_yaml_path , backup_project_database_yaml_path )
13
- end
4
+ Metasploit ::Framework ::Database ::Cucumber . backup_project_configurations
14
5
end
15
6
16
7
Given /^the project "database.yml" exists with:$/ do |file_content |
17
- if File . exist? ( project_database_yaml_path )
18
- File . rename ( project_database_yaml_path , backup_project_database_yaml_path )
19
- end
20
-
21
- write_file ( project_database_yaml_path , file_content )
8
+ Metasploit ::Framework ::Database ::Cucumber . backup_project_configurations
9
+ write_file ( Metasploit ::Framework ::Database ::Cucumber . project_configurations_path , file_content )
22
10
end
23
11
24
12
After do
25
- if File . exist? ( backup_project_database_yaml_path )
26
- File . rename ( backup_project_database_yaml_path , project_database_yaml_path )
27
- end
13
+ Metasploit ::Framework ::Database ::Cucumber . restore_project_configurations
28
14
end
Original file line number Diff line number Diff line change
1
+ require 'metasploit/framework/database'
2
+
3
+ module Metasploit ::Framework ::Database ::Cucumber
4
+ def self . project_configurations_path
5
+ Rails . root . join ( 'config' , 'database.yml' ) . to_path
6
+ end
7
+
8
+ def self . backup_project_configurations
9
+ if File . exist? ( project_configurations_path )
10
+ # assume that the backup file is from a previously aborted run and it contains the real database.yml data, so
11
+ # just delete the fake database.yml and the After hook will restore the real database.yml from the backup location
12
+ if File . exist? ( backup_project_configurations_path )
13
+ File . delete ( project_configurations_path )
14
+ else
15
+ # project contains the real database.yml and there was no previous, aborted run.
16
+ File . rename ( project_configurations_path , backup_project_configurations_path )
17
+ end
18
+ end
19
+ end
20
+
21
+ def self . backup_project_configurations_path
22
+ "#{ project_configurations_path } .cucumber.bak"
23
+ end
24
+
25
+ def self . restore_project_configurations
26
+ if File . exist? ( backup_project_configurations_path )
27
+ if File . exist? ( project_configurations_path )
28
+ # Remove fake, leftover database.yml
29
+ File . delete ( project_configurations_path )
30
+ end
31
+
32
+ File . rename ( backup_project_configurations_path , project_configurations_path )
33
+ end
34
+ end
35
+ end
36
+
Original file line number Diff line number Diff line change 54
54
task 'db:test:prepare' do
55
55
end
56
56
57
+ task 'db:config:restore' do
58
+ require 'metasploit/framework/database/cucumber'
59
+ Metasploit ::Framework ::Database ::Cucumber . restore_project_configurations
60
+ end
61
+
62
+ # Restore the config/database.yml from config/database.cucumber.yml before attempting to copy development to test
63
+ # database in order to recover from interrupted cucumber runs
64
+ task 'environment' => 'db:config:restore'
65
+
57
66
task :stats => 'cucumber:statsetup'
58
67
rescue LoadError
59
68
desc 'cucumber rake task not available (cucumber not installed)'
You can’t perform that action at this time.
0 commit comments