spe_cuke 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ vendor/*
4
+ .bundle/*
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source :gemcutter
2
+
3
+ gem 'rake'
4
+ group :test do
5
+ gem 'rspec'
6
+ end
7
+ # Specify your gem's dependencies in spe_cuke.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ spe_cuke (0.1.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ rake (0.8.7)
10
+ rspec (1.3.0)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ bundler (>= 1.0.0.rc.5)
17
+ rake
18
+ rspec
19
+ spe_cuke!
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler'
2
+ require 'bundler/setup'
3
+ require 'spec/rake/spectask'
4
+
5
+ Bundler::GemHelper.install_tasks
6
+ Spec::Rake::SpecTask.new
data/bin/sc ADDED
@@ -0,0 +1,20 @@
1
+ # vim:set filetype=ruby:
2
+
3
+ require 'optparse'
4
+
5
+ require 'spe_cuke'
6
+ require 'spe_cuke/environment'
7
+ require 'spe_cuke/target'
8
+
9
+ opt = OptionParser.new
10
+ $option = {:root => '.'}
11
+ opt.on('-l', '--line=N', Integer) {|l| $option[:line] = l }
12
+ opt.on('-r', '--rake', TrueClass) {|b| $option[:prefer_rake] = b }
13
+ opt.parse!(ARGV)
14
+
15
+ SpeCuke::Target.for(ARGV.first).new(
16
+ SpeCuke::Environment.new($option[:root], :prefer_rake => $option[:prefer_rake]),
17
+ ARGV.first,
18
+ $option[:line]
19
+ ).execute!
20
+
@@ -0,0 +1,46 @@
1
+ require 'rbconfig'
2
+ require 'pathname'
3
+ require 'yaml'
4
+
5
+ module SpeCuke
6
+ class Environment
7
+ def initialize(root = '.', options = {})
8
+ @root = Pathname.new(root)
9
+ @options = options
10
+ end
11
+
12
+ def command(cmd)
13
+ bundlized? ? bundle_exec << cmd : [executable_name(cmd)]
14
+ end
15
+
16
+ def bundlized?
17
+ (@root + 'Gemfile').exist?
18
+ end
19
+
20
+ def gem_format_executable?
21
+ @_gemrc = YAML.load_file(Pathname.new(ENV['HOME']) + '.gemrc')
22
+ @_gemrc['gem'].include?('--format-executable')
23
+ end
24
+
25
+ def prefer_rake?
26
+ has_rakefile? && @options[:prefer_rake]
27
+ end
28
+
29
+ def has_rakefile?
30
+ (@root + 'Rakefile').exist?
31
+ end
32
+
33
+ private
34
+ def bundle_exec
35
+ [executable_name('bundle'), 'exec']
36
+ end
37
+
38
+ def executable_name(base)
39
+ if gem_format_executable?
40
+ base + RbConfig::CONFIG['RUBY_INSTALL_NAME'].sub(/\Aruby/, '')
41
+ else
42
+ base
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+
2
+ module SpeCuke
3
+ module Target
4
+ class Base
5
+ class << self
6
+ attr_reader :subclasses
7
+
8
+ def inherited(sub)
9
+ @subclasses << sub
10
+ end
11
+ end
12
+ @subclasses = []
13
+
14
+ def initialize(env, fname, line = nil)
15
+ @fname = fname
16
+ @line = line
17
+ @env = env
18
+ end
19
+
20
+ def execute!
21
+ commands = @env.prefer_rake? ? rake_commands : raw_commands
22
+ SpeCuke.wrap_execute!( commands.flatten )
23
+ end
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,37 @@
1
+ require 'spe_cuke/target/base'
2
+
3
+ module SpeCuke::Target
4
+ class Rspec < Base
5
+ class << self
6
+ attr_accessor :default_options
7
+ def suitable?(file)
8
+ file =~ /_spec\.rb/
9
+ end
10
+ end
11
+ self.default_options = ['--color']
12
+
13
+ private
14
+ def raw_commands
15
+ cmds = [@env.command('spec')]
16
+ cmds << self.class.default_options
17
+ if @line
18
+ cmds << '-fn' # XXX
19
+ end
20
+ cmds << fn_and_line
21
+ end
22
+
23
+ def rake_commands
24
+ cmds = [@env.command('rake'), 'spec', "SPEC=#{fn_and_line}"]
25
+ if @line
26
+ cmds << ["SPEC_OPTS=#{self.class.default_options.join(' ')} --format nested"]
27
+ else
28
+ # use spec/spec.opts instead of self.class.default_options
29
+ end
30
+ cmds
31
+ end
32
+
33
+ def fn_and_line
34
+ @line ? "#{@fname}:#{@line}" : @fname
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,10 @@
1
+ require 'spe_cuke/target/rspec'
2
+
3
+ module SpeCuke
4
+ module Target
5
+ def for(file)
6
+ Base.subclasses.detect{|t| t.suitable?(file) }
7
+ end
8
+ module_function :for
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module SpeCuke
2
+ VERSION = "0.1.1"
3
+ end
data/lib/spe_cuke.rb ADDED
@@ -0,0 +1,8 @@
1
+ module SpeCuke
2
+ extend self
3
+
4
+ def wrap_execute!(commands)
5
+ puts commands.join(' ')
6
+ system(*commands)
7
+ end
8
+ end
data/spe_cuke.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
3
+ require 'spe_cuke/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "spe_cuke"
7
+ s.version = SpeCuke::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["MOROHASHI Kyosuke"]
10
+ s.email = ["moronatural@gmail.com"]
11
+ s.homepage = "http://rubygems.org/gems/spe_cuke"
12
+ s.summary = "Provides common interface for rake spec or bin/spec."
13
+ s.description = "An abstraction command for testing frameworks and invokation methods of them."
14
+
15
+ s.required_rubygems_version = ">= 1.3.6"
16
+ s.rubyforge_project = "spe_cuke"
17
+
18
+ s.add_development_dependency "bundler", ">= 1.0.0.rc.5"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.executables = `git ls-files`.split("\n").select{|f| f =~ /^bin/}.map{|bin| File.basename(bin) }
22
+ s.require_path = 'lib'
23
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ require 'spe_cuke/environment'
3
+
4
+ module SpeCuke
5
+
6
+ describe Environment do
7
+ before do
8
+ @env = Environment.new
9
+ @env.stub(:bundlized?).and_return false
10
+ @env.stub(:gem_format_executable?).and_return false
11
+ end
12
+ subject { @env.command('rails') }
13
+
14
+ describe '#command()' do
15
+ context 'bundlized & --gem_format_executable' do
16
+ before do
17
+ @env.stub(:bundlized?).and_return true
18
+ @env.stub(:gem_format_executable?).and_return true
19
+ end
20
+
21
+ it { should == %w[bundle18 exec rails] }
22
+ end
23
+
24
+ context 'bundlized' do
25
+ before do
26
+ @env.stub(:bundlized?).and_return true
27
+ end
28
+
29
+ it { should == %w[bundle exec rails] }
30
+ end
31
+
32
+ context '--gem_format_executable' do
33
+ before do
34
+ @env.stub(:gem_format_executable?).and_return true
35
+ end
36
+
37
+ it { should == %w[rails18] }
38
+ end
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+ require 'spe_cuke/target'
3
+ require 'spe_cuke/environment'
4
+
5
+ module SpeCuke
6
+
7
+ describe Target do
8
+ it { Target.for('spec/foo/bar_spec.rb').should == Target::Rspec }
9
+ end
10
+
11
+ describe Target::Rspec 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::Rspec.default_options = ['--color']
18
+ end
19
+
20
+ context 'spec/foo/bar_spec.rb' do
21
+ before do
22
+ @env.stub!(:has_rakefile?).and_return false
23
+ @target = Target::Rspec.new(@env, 'spec/foo/bar_spec.rb')
24
+ SpeCuke.should_receive(:wrap_execute!).with(%w[spec --color spec/foo/bar_spec.rb])
25
+ end
26
+
27
+ it(%q[spec --color spec/foo/bar_spec.rb]){ @target.execute! }
28
+ end
29
+
30
+
31
+ context 'spec/foo/bar_spec.rb on line 40' do
32
+ before do
33
+ @env.stub!(:has_rakefile?).and_return false
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])
36
+ end
37
+
38
+ it(%q[spec --color -l 40 spec/foo/bar_spec.rb]){ @target.execute! }
39
+ end
40
+
41
+ context 'spec/foo/bar_spec.rb w/Rakefile' do
42
+ before do
43
+ @env.stub!(:has_rakefile?).and_return true
44
+ @target = Target::Rspec.new(@env, 'spec/foo/bar_spec.rb')
45
+ SpeCuke.should_receive(:wrap_execute!).with(%w[rake spec SPEC=spec/foo/bar_spec.rb])
46
+ end
47
+
48
+ it(%q[rake spec SPEC=spec/foo/bar_spec.rb]){ @target.execute! }
49
+ end
50
+
51
+ context 'spec/foo/bar_spec.rb w/Rakefile on line 40' do
52
+ before do
53
+ @env.stub!(:has_rakefile?).and_return true
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])
56
+ end
57
+
58
+ it(%q[rake spec SPEC=spec/foo/bar_spec.rb:40]){ @target.execute! }
59
+ end
60
+ end
61
+
62
+ end
63
+
@@ -0,0 +1,2 @@
1
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
2
+
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spe_cuke
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - MOROHASHI Kyosuke
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-09 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 15424063
28
+ segments:
29
+ - 1
30
+ - 0
31
+ - 0
32
+ - rc
33
+ - 5
34
+ version: 1.0.0.rc.5
35
+ requirement: *id001
36
+ type: :development
37
+ name: bundler
38
+ prerelease: false
39
+ description: An abstraction command for testing frameworks and invokation methods of them.
40
+ email:
41
+ - moronatural@gmail.com
42
+ executables:
43
+ - sc
44
+ extensions: []
45
+
46
+ extra_rdoc_files: []
47
+
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - Rakefile
53
+ - bin/sc
54
+ - lib/spe_cuke.rb
55
+ - lib/spe_cuke/environment.rb
56
+ - lib/spe_cuke/target.rb
57
+ - lib/spe_cuke/target/base.rb
58
+ - lib/spe_cuke/target/rspec.rb
59
+ - lib/spe_cuke/version.rb
60
+ - spe_cuke.gemspec
61
+ - spec/spe_cuke/environment_spec.rb
62
+ - spec/spe_cuke/target_rspec_spec.rb
63
+ - spec/spec_helper.rb
64
+ has_rdoc: true
65
+ homepage: http://rubygems.org/gems/spe_cuke
66
+ licenses: []
67
+
68
+ post_install_message:
69
+ rdoc_options: []
70
+
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 23
88
+ segments:
89
+ - 1
90
+ - 3
91
+ - 6
92
+ version: 1.3.6
93
+ requirements: []
94
+
95
+ rubyforge_project: spe_cuke
96
+ rubygems_version: 1.3.7
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Provides common interface for rake spec or bin/spec.
100
+ test_files: []
101
+