-
-
Notifications
You must be signed in to change notification settings - Fork 764
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Feature: configure | ||
|
||
Use --configure to generate configuration files. | ||
|
||
Currently, the only supported argument is "autotest", which creates | ||
a autotest/discover.rb file in your project root directory. | ||
|
||
Background: | ||
Given a directory named "rspec_project" | ||
And I cd to "rspec_project" | ||
|
||
Scenario: generate autotest directory and discover file | ||
When I run "rspec --configure autotest" | ||
Then the following directories should exist: | ||
| autotest | | ||
And the following files should exist: | ||
| autotest/discover.rb | | ||
And the file "autotest/discover.rb" should contain "Autotest.add_discovery" | ||
And the stdout should contain "autotest/discover.rb has been added" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module RSpec | ||
module Core | ||
class CommandLineConfiguration | ||
attr_reader :command | ||
|
||
def initialize(cmd) | ||
@command = cmd | ||
end | ||
|
||
def run | ||
case @command | ||
when 'autotest' then Autotest.generate | ||
else raise ArgumentError, "#{@command} is not a valid option" | ||
end | ||
end | ||
|
||
class Autotest | ||
class << self | ||
def generate | ||
create_autotest_directory | ||
create_discover_file | ||
puts "autotest/discover.rb has been added" | ||
end | ||
|
||
def create_autotest_directory | ||
Dir.mkdir('autotest') unless File.exist?('autotest') | ||
end | ||
|
||
def create_discover_file | ||
optionally_remove_discover_file if discover_file_exists? | ||
File.open(discover_file_path, 'w') do |file| | ||
file << 'Autotest.add_discovery { "rspec2" }' | ||
end | ||
end | ||
|
||
def optionally_remove_discover_file | ||
print "Discover file already exists, overwrite [y/N]? " | ||
exit if gets !~ /y/i | ||
FileUtils.rm_rf(discover_file_path) | ||
end | ||
|
||
def discover_file_exists? | ||
File.exist?(discover_file_path) | ||
end | ||
|
||
def discover_file_path | ||
File.join('autotest', 'discover.rb') | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'spec_helper' | ||
|
||
module RSpec::Core | ||
describe CommandLineConfiguration do | ||
describe '#run' do | ||
context 'given autotest command' do | ||
let(:config) { described_class.new('autotest') } | ||
|
||
it 'calls Autotest.generate' do | ||
described_class::Autotest.should_receive(:generate) | ||
config.run | ||
end | ||
end | ||
|
||
context 'given unsupported command' do | ||
let(:config) { described_class.new('unsupported') } | ||
|
||
it 'raises ArgumentError' do | ||
lambda { config.run }.should( | ||
raise_error(ArgumentError, 'unsupported is not a valid option') | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |