File tree Expand file tree Collapse file tree 5 files changed +102
-1
lines changed Expand file tree Collapse file tree 5 files changed +102
-1
lines changed Original file line number Diff line number Diff line change
1
+ Feature : configure
2
+
3
+ Use --configure to generate configuration files.
4
+
5
+ Currently, the only supported argument is "autotest" , which creates
6
+ a autotest/discover.rb file in your project root directory.
7
+
8
+ Background :
9
+ Given a directory named "rspec_project"
10
+ And I cd to "rspec_project"
11
+
12
+ Scenario : generate autotest directory and discover file
13
+ When I run "rspec --configure autotest"
14
+ Then the following directories should exist:
15
+ | autotest |
16
+ And the following files should exist:
17
+ | autotest /discover .rb |
18
+ And the file "autotest/discover.rb" should contain "Autotest.add_discovery"
19
+ And the stdout should contain "autotest/discover.rb has been added"
Original file line number Diff line number Diff line change 13
13
require 'rspec/core/around_proxy'
14
14
require 'rspec/core/world'
15
15
require 'rspec/core/configuration'
16
+ require 'rspec/core/command_line_configuration'
16
17
require 'rspec/core/option_parser'
17
18
require 'rspec/core/configuration_options'
18
19
require 'rspec/core/command_line'
Original file line number Diff line number Diff line change
1
+ module RSpec
2
+ module Core
3
+ class CommandLineConfiguration
4
+ attr_reader :command
5
+
6
+ def initialize ( cmd )
7
+ @command = cmd
8
+ end
9
+
10
+ def run
11
+ case @command
12
+ when 'autotest' then Autotest . generate
13
+ else raise ArgumentError , "#{ @command } is not a valid option"
14
+ end
15
+ end
16
+
17
+ class Autotest
18
+ def self . generate
19
+ create_autotest_directory
20
+ create_discover_file
21
+ puts "autotest/discover.rb has been added"
22
+ end
23
+
24
+ def self . create_autotest_directory
25
+ Dir . mkdir ( 'autotest' ) unless File . exist? ( 'autotest' )
26
+ end
27
+
28
+ def self . create_discover_file
29
+ optionally_remove_discover_file if discover_file_exists?
30
+
31
+ File . open ( discover_file_path , 'w' ) do |file |
32
+ file << 'Autotest.add_discovery { "rspec2" }'
33
+ end
34
+ end
35
+
36
+ def optionally_remove_discover_file
37
+ print "Discover file already exists, overwrite [Y/n]? "
38
+ exit if gets != 'Y'
39
+ FileUtils . rm_rf ( discover_file_path )
40
+ end
41
+
42
+ def self . discover_file_exists?
43
+ File . exist? ( discover_file_path )
44
+ end
45
+
46
+ def self . discover_file_path
47
+ File . join ( 'autotest' , 'discover.rb' )
48
+ end
49
+ end
50
+ end
51
+ end
Original file line number Diff line number Diff line change @@ -85,11 +85,15 @@ def parser(options)
85
85
parser . on ( '-X' , '--drb' , 'Run examples via DRb' ) do |o |
86
86
options [ :drb ] = true
87
87
end
88
+
89
+ parser . on ( '--configure COMMAND' , 'Generate configuration files' ) do |cmd |
90
+ CommandLineConfiguration . new ( cmd ) . run
91
+ exit
92
+ end
88
93
89
94
parser . on ( '--drb-port [PORT]' , 'Port to connect to on the DRb server' ) do |o |
90
95
options [ :drb_port ] = o . to_i
91
96
end
92
-
93
97
end
94
98
end
95
99
end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ module RSpec ::Core
4
+ describe CommandLineConfiguration do
5
+ describe '#run' do
6
+ context 'given autotest command' do
7
+ let ( :config ) { described_class . new ( 'autotest' ) }
8
+
9
+ it 'calls Autotest.generate' do
10
+ described_class ::Autotest . should_receive ( :generate )
11
+ config . run
12
+ end
13
+ end
14
+
15
+ context 'given unsupported command' do
16
+ let ( :config ) { described_class . new ( 'unsupported' ) }
17
+
18
+ it 'raises ArgumentError' do
19
+ lambda { config . run } . should (
20
+ raise_error ( ArgumentError , 'unsupported is not a valid option' )
21
+ )
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
You can’t perform that action at this time.
0 commit comments