spe_cuke 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spe_cuke (0.1.1)
4
+ spe_cuke (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.rdoc ADDED
@@ -0,0 +1,68 @@
1
+ = SpeCuke
2
+
3
+ A simple helper command to run rspec or cucumber tests.
4
+
5
+ == Description
6
+
7
+ spe_cuke provides command `sc'.
8
+
9
+ This helps you to run spec/cuke test in various environments, such as bundler-ized?, --format-executable in .gemrc or so.
10
+
11
+ === Example
12
+ The command below invokes
13
+
14
+ sc --line 32 spec/foobar/foobar_spec.rb
15
+
16
+ when bundlized(Gemfile exists)
17
+
18
+ bundle exec spec --color --fn spec/foobar/foobar_spec.rb:32
19
+
20
+ when not bundlized but --format-executable in .gemrc
21
+
22
+ spec18 --color --fn spec/foobar/foobar_spec.rb:32
23
+
24
+ and has option to specify invoking via rake.
25
+
26
+ sc -r --line 32 spec/foobar/foobar_spec.rb #=>
27
+ bundle exec rake18 spec SPEC=spec/foobar/foobar_spec.rb:32
28
+
29
+ == Vim script
30
+
31
+ append below to your .vimrc or so.
32
+
33
+ function s:SetupSpeCuke()
34
+ command! RunTestFile exe '!sc ' . expand('%:p')
35
+ command! RunTestCase exe '!sc --line ' . line('.') . ' ' . expand('%:p')
36
+
37
+ nnoremap -tf :RunTestFile<CR>
38
+ nnoremap -tc :RunTestCase<CR>
39
+ endfunction
40
+
41
+ au BufRead,BufNewFile *_spec.rb,*.feature call s:SetupSpeCuke()
42
+
43
+ Then
44
+
45
+ You type '-tf' in normal mode, invokes 'sc --line <current_line> <current_file>' and
46
+ test around current line's example/scenario.
47
+
48
+ You type '-tc' in normal mode, invokes 'sc <current_file>' and test current file.
49
+
50
+ == Planning features.
51
+
52
+ * spork support
53
+ * run spec from name-paired script (run spec/spe_cuke/environment_spec.rb from lib/spe_cuke/environment.rb)
54
+
55
+ == Installation
56
+
57
+ gem install spe_cuke
58
+
59
+ == Acknowledgements
60
+
61
+ spe_cuke's development has been supported by Eiwa System Management,Inc.
62
+
63
+ == Copyright
64
+
65
+ Author:: MOROHASHI Kyosuke <moronatural@gmail.com>
66
+ Copyright:: Copyright (c) 2010 MOROHASHI Kyosuke
67
+ License:: MIT
68
+
@@ -37,10 +37,14 @@ module SpeCuke
37
37
 
38
38
  def executable_name(base)
39
39
  if gem_format_executable?
40
- base + RbConfig::CONFIG['RUBY_INSTALL_NAME'].sub(/\Aruby/, '')
40
+ base + bin_suffix
41
41
  else
42
42
  base
43
43
  end
44
44
  end
45
+
46
+ def bin_suffix
47
+ RbConfig::CONFIG['RUBY_INSTALL_NAME'].sub(/\Aruby/, '')
48
+ end
45
49
  end
46
50
  end
@@ -8,6 +8,9 @@ module SpeCuke
8
8
  def inherited(sub)
9
9
  @subclasses << sub
10
10
  end
11
+
12
+ def default_options; @@default_options; end
13
+ def default_options=(opt); @@default_options = opt; end
11
14
  end
12
15
  @subclasses = []
13
16
 
@@ -0,0 +1,36 @@
1
+ require 'spe_cuke/target/base'
2
+
3
+ module SpeCuke::Target
4
+ class Cucumber < Base
5
+ class << self
6
+ def suitable?(file)
7
+ file =~ /\.feature\Z/
8
+ end
9
+ end
10
+ self.default_options = ['--color']
11
+
12
+ private
13
+ def raw_commands
14
+ cmds = [@env.command('cucumber')]
15
+ cmds << self.class.default_options
16
+ if @line
17
+ cmds << '--format=pretty' # XXX
18
+ end
19
+ cmds << fn_and_line
20
+ end
21
+
22
+ def rake_commands
23
+ cmds = [@env.command('rake'), 'cucumber', "FEATURE=#{fn_and_line}"]
24
+ if @line
25
+ cmds << ["CUCUMBER_FORMAT=pretty"]
26
+ else
27
+ # use spec/spec.opts instead of self.class.default_options
28
+ end
29
+ cmds
30
+ end
31
+
32
+ def fn_and_line
33
+ @line ? "#{@fname}:#{@line}" : @fname
34
+ end
35
+ end
36
+ end
@@ -1,4 +1,5 @@
1
1
  require 'spe_cuke/target/rspec'
2
+ require 'spe_cuke/target/cucumber'
2
3
 
3
4
  module SpeCuke
4
5
  module Target
@@ -1,3 +1,3 @@
1
1
  module SpeCuke
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -6,6 +6,7 @@ module SpeCuke
6
6
  describe Environment do
7
7
  before do
8
8
  @env = Environment.new
9
+ @env.stub(:bin_suffix).and_return '187'
9
10
  @env.stub(:bundlized?).and_return false
10
11
  @env.stub(:gem_format_executable?).and_return false
11
12
  end
@@ -18,7 +19,7 @@ describe Environment do
18
19
  @env.stub(:gem_format_executable?).and_return true
19
20
  end
20
21
 
21
- it { should == %w[bundle18 exec rails] }
22
+ it { should == %w[bundle187 exec rails] }
22
23
  end
23
24
 
24
25
  context 'bundlized' do
@@ -34,7 +35,7 @@ describe Environment do
34
35
  @env.stub(:gem_format_executable?).and_return true
35
36
  end
36
37
 
37
- it { should == %w[rails18] }
38
+ it { should == %w[rails187] }
38
39
  end
39
40
  end
40
41
  end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'spe_cuke/target'
3
+ require 'spe_cuke/environment'
4
+
5
+ module SpeCuke
6
+
7
+ describe Target, 'detection' do
8
+ it { Target.for('features/foo/some_feature.feature').should == Target::Cucumber }
9
+ end
10
+
11
+ describe Target::Cucumber do
12
+ before do
13
+ @env = Environment.new
14
+ @env.stub!(:bundlized?).and_return false
15
+ @env.stub!(:gem_format_executable?).and_return false
16
+
17
+ Target::Cucumber.default_options = ['--color']
18
+ end
19
+
20
+ [
21
+ [nil, false, %w[cucumber --color features/foo/some_feature.features]],
22
+ [40, false, %w[cucumber --color --format=pretty features/foo/some_feature.features:40]],
23
+ [nil, true, %w[rake cucumber FEATURE=features/foo/some_feature.features]],
24
+ [40, true, %w[rake cucumber FEATURE=features/foo/some_feature.features:40 CUCUMBER_FORMAT=pretty]],
25
+ ].each do |line, prefer_rake, expectation|
26
+ context "features/foo/some_feature.features| line:#{line}/rake:#{prefer_rake}" do
27
+ before do
28
+ @env.stub!(:prefer_rake?).and_return prefer_rake
29
+ @target = Target::Cucumber.new(@env, 'features/foo/some_feature.features', line)
30
+ SpeCuke.should_receive(:wrap_execute!).with(expectation)
31
+ end
32
+
33
+ it("should invoke `#{expectation.join(' ')}'"){ @target.execute! }
34
+ end
35
+ end
36
+ end
37
+
38
+ end
39
+
@@ -19,7 +19,7 @@ describe Target::Rspec do
19
19
 
20
20
  context 'spec/foo/bar_spec.rb' do
21
21
  before do
22
- @env.stub!(:has_rakefile?).and_return false
22
+ @env.stub!(:prefer_rake?).and_return false
23
23
  @target = Target::Rspec.new(@env, 'spec/foo/bar_spec.rb')
24
24
  SpeCuke.should_receive(:wrap_execute!).with(%w[spec --color spec/foo/bar_spec.rb])
25
25
  end
@@ -30,9 +30,9 @@ describe Target::Rspec do
30
30
 
31
31
  context 'spec/foo/bar_spec.rb on line 40' do
32
32
  before do
33
- @env.stub!(:has_rakefile?).and_return false
33
+ @env.stub!(:prefer_rake?).and_return false
34
34
  @target = Target::Rspec.new(@env, 'spec/foo/bar_spec.rb', 40)
35
- SpeCuke.should_receive(:wrap_execute!).with(%w[spec --color -l 40 -fn spec/foo/bar_spec.rb])
35
+ SpeCuke.should_receive(:wrap_execute!).with(%w[spec --color -fn spec/foo/bar_spec.rb:40])
36
36
  end
37
37
 
38
38
  it(%q[spec --color -l 40 spec/foo/bar_spec.rb]){ @target.execute! }
@@ -40,7 +40,7 @@ describe Target::Rspec do
40
40
 
41
41
  context 'spec/foo/bar_spec.rb w/Rakefile' do
42
42
  before do
43
- @env.stub!(:has_rakefile?).and_return true
43
+ @env.stub!(:prefer_rake?).and_return true
44
44
  @target = Target::Rspec.new(@env, 'spec/foo/bar_spec.rb')
45
45
  SpeCuke.should_receive(:wrap_execute!).with(%w[rake spec SPEC=spec/foo/bar_spec.rb])
46
46
  end
@@ -50,9 +50,9 @@ describe Target::Rspec do
50
50
 
51
51
  context 'spec/foo/bar_spec.rb w/Rakefile on line 40' do
52
52
  before do
53
- @env.stub!(:has_rakefile?).and_return true
53
+ @env.stub!(:prefer_rake?).and_return true
54
54
  @target = Target::Rspec.new(@env, 'spec/foo/bar_spec.rb', 40)
55
- SpeCuke.should_receive(:wrap_execute!).with(%w[rake spec SPEC=spec/foo/bar_spec.rb:40])
55
+ SpeCuke.should_receive(:wrap_execute!).with(["rake", "spec", "SPEC=spec/foo/bar_spec.rb:40", "SPEC_OPTS=--color --format nested"])
56
56
  end
57
57
 
58
58
  it(%q[rake spec SPEC=spec/foo/bar_spec.rb:40]){ @target.execute! }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spe_cuke
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - MOROHASHI Kyosuke
@@ -49,16 +49,19 @@ files:
49
49
  - .gitignore
50
50
  - Gemfile
51
51
  - Gemfile.lock
52
+ - README.rdoc
52
53
  - Rakefile
53
54
  - bin/sc
54
55
  - lib/spe_cuke.rb
55
56
  - lib/spe_cuke/environment.rb
56
57
  - lib/spe_cuke/target.rb
57
58
  - lib/spe_cuke/target/base.rb
59
+ - lib/spe_cuke/target/cucumber.rb
58
60
  - lib/spe_cuke/target/rspec.rb
59
61
  - lib/spe_cuke/version.rb
60
62
  - spe_cuke.gemspec
61
63
  - spec/spe_cuke/environment_spec.rb
64
+ - spec/spe_cuke/target_cucumber_spec.rb
62
65
  - spec/spe_cuke/target_rspec_spec.rb
63
66
  - spec/spec_helper.rb
64
67
  has_rdoc: true