polyamory 0.6.0 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -1
- data/lib/polyamory.rb +1 -1
- data/lib/polyamory/bats.rb +107 -0
- data/lib/polyamory/cucumber.rb +1 -1
- data/lib/polyamory/rspec.rb +1 -1
- data/lib/polyamory/runner.rb +4 -3
- data/lib/polyamory/test_unit.rb +6 -2
- data/test/test_runner.rb +1 -1
- metadata +3 -2
data/README.md
CHANGED
@@ -10,8 +10,20 @@ Frameworks supported:
|
|
10
10
|
* Cucumber in `features/**/*.feature`
|
11
11
|
* RSpec + Shoulda in `spec/**/*_spec.rb`
|
12
12
|
* test/unit, Shoulda, or anything else in `test/**/*_test.rb` or `test/**/test*.rb`
|
13
|
+
* Bats in `test/*.bats`
|
13
14
|
|
14
|
-
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
# Mac OS X
|
18
|
+
brew install https://github.com/mislav/polyamory/raw/master/brew/polyamory.rb
|
19
|
+
|
20
|
+
# other
|
21
|
+
gem i polyamory
|
22
|
+
|
23
|
+
# alias for brevity
|
24
|
+
alias pam=polyamory
|
25
|
+
|
26
|
+
## Features
|
15
27
|
|
16
28
|
* `polyamory` - Runs the full test suite for any project. For example, it will
|
17
29
|
run all of the following:
|
data/lib/polyamory.rb
CHANGED
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'polyamory/rooted_pathname'
|
2
|
+
require 'polyamory/command'
|
3
|
+
|
4
|
+
module Polyamory
|
5
|
+
# Internal: Deals with finding Bats files to test
|
6
|
+
# https://github.com/sstephenson/bats#readme
|
7
|
+
class Bats
|
8
|
+
attr_reader :context
|
9
|
+
|
10
|
+
def initialize context
|
11
|
+
@context = context
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_dir
|
15
|
+
@test_dir ||= context.root + 'test'
|
16
|
+
end
|
17
|
+
|
18
|
+
def file_pattern dir
|
19
|
+
"#{dir}/*.bats"
|
20
|
+
end
|
21
|
+
|
22
|
+
def handle? path
|
23
|
+
path.extname == '.bats' || !find_files(path).empty?
|
24
|
+
end
|
25
|
+
|
26
|
+
def find_files dir = test_dir
|
27
|
+
glob file_pattern(dir)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Internal: Memoized find_files in primary dir
|
31
|
+
def all_matching_files
|
32
|
+
@all_matching_files ||= find_files
|
33
|
+
end
|
34
|
+
|
35
|
+
# Public: Resolve a set of files, directories, and patterns to a list of
|
36
|
+
# paths to test.
|
37
|
+
def resolve_paths names
|
38
|
+
if context.tag_filters.any?
|
39
|
+
# Bats doesn't support tags
|
40
|
+
[]
|
41
|
+
elsif names.any?
|
42
|
+
paths = []
|
43
|
+
for name in names
|
44
|
+
paths.concat Array(resolve_name name)
|
45
|
+
end
|
46
|
+
paths
|
47
|
+
else
|
48
|
+
[test_dir]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def resolve_name name
|
53
|
+
resolve_as_directory(name) or
|
54
|
+
resolve_as_filename(name) or
|
55
|
+
resolve_as_file_pattern(name) or
|
56
|
+
raise "nothing resolved from #{name}"
|
57
|
+
end
|
58
|
+
|
59
|
+
# "functional" => "test/functional/**"
|
60
|
+
# "test/functional" => "test/functional/**"
|
61
|
+
def resolve_as_directory name
|
62
|
+
[test_dir + name, context.root + name].detect { |dir| handle?(dir) }
|
63
|
+
end
|
64
|
+
|
65
|
+
# "test/unit/hello.bats"
|
66
|
+
def resolve_as_filename name
|
67
|
+
file = context.root + name
|
68
|
+
file if file.file? and handle?(file)
|
69
|
+
end
|
70
|
+
|
71
|
+
# "word" => "test/**" that match "word"
|
72
|
+
def resolve_as_file_pattern name
|
73
|
+
pattern = /(?:\b|_)#{Regexp.escape name}(?:\b|_)/
|
74
|
+
all_matching_files.select {|p| p =~ pattern }
|
75
|
+
end
|
76
|
+
|
77
|
+
# Public: From a list of paths, yank the ones that this knows how to handle,
|
78
|
+
# and build test jobs from it.
|
79
|
+
def pick_jobs paths
|
80
|
+
to_test = []
|
81
|
+
paths.reject! do |path|
|
82
|
+
if handle? path
|
83
|
+
to_test << path
|
84
|
+
true
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
unless to_test.empty?
|
89
|
+
excess = to_test.slice!(1..-1)
|
90
|
+
warn "warning: bats can only accept one filename; skipping #{excess.map {|p| p.relative }.join(' ')}" unless excess.empty?
|
91
|
+
[test_command(to_test)]
|
92
|
+
else
|
93
|
+
[]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_command paths
|
98
|
+
Command.new ['bats'] do |test_job|
|
99
|
+
test_job.concat paths.map {|p| p.relative }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def glob pattern
|
104
|
+
RootedPathname.glob pattern, context.root
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
data/lib/polyamory/cucumber.rb
CHANGED
data/lib/polyamory/rspec.rb
CHANGED
data/lib/polyamory/runner.rb
CHANGED
@@ -2,6 +2,7 @@ require 'polyamory/rooted_pathname'
|
|
2
2
|
require 'polyamory/test_unit'
|
3
3
|
require 'polyamory/rspec'
|
4
4
|
require 'polyamory/cucumber'
|
5
|
+
require 'polyamory/bats'
|
5
6
|
|
6
7
|
module Polyamory
|
7
8
|
# Public: Collects test jobs in the root directory and runs them.
|
@@ -45,8 +46,8 @@ module Polyamory
|
|
45
46
|
def bundle_exec?
|
46
47
|
return @bundle_exec if defined? @bundle_exec
|
47
48
|
if (setting = options.fetch(:bundler)).nil?
|
48
|
-
setting =
|
49
|
-
|
49
|
+
setting = ENV['RUBYOPT'] !~ /\br?bundler\/setup\b/ &&
|
50
|
+
( !ENV['BUNDLE_GEMFILE'].to_s.empty? || (root + 'Gemfile').exist? )
|
50
51
|
end
|
51
52
|
@bundle_exec = setting
|
52
53
|
end
|
@@ -71,7 +72,7 @@ module Polyamory
|
|
71
72
|
end
|
72
73
|
|
73
74
|
def collect_jobs
|
74
|
-
[TestUnit, RSpec, Cucumber].inject([]) do |jobs, klass|
|
75
|
+
[TestUnit, RSpec, Cucumber, Bats].inject([]) do |jobs, klass|
|
75
76
|
framework = klass.new self
|
76
77
|
paths = framework.resolve_paths @names
|
77
78
|
jobs.concat framework.pick_jobs(paths)
|
data/lib/polyamory/test_unit.rb
CHANGED
@@ -126,15 +126,19 @@ module Polyamory
|
|
126
126
|
RootedPathname.glob pattern, context.root
|
127
127
|
end
|
128
128
|
|
129
|
+
def rails?
|
130
|
+
(context.root + 'config/environment.rb').exist?
|
131
|
+
end
|
132
|
+
|
129
133
|
def add_ruby_options cmd
|
130
134
|
opts = []
|
131
135
|
opts << '-w' if context.warnings?
|
132
|
-
opts <<
|
136
|
+
opts << "-Ilib:#{test_dir.basename}" unless rails?
|
133
137
|
for path in context.load_paths
|
134
138
|
opts << "-I#{path}"
|
135
139
|
end
|
136
140
|
opts << '%'
|
137
|
-
cmd.env['RUBYOPT'] = opts.join(' ')
|
141
|
+
cmd.env['RUBYOPT'] = opts.join(' ') if opts.size > 1
|
138
142
|
end
|
139
143
|
|
140
144
|
def testunit_options
|
data/test/test_runner.rb
CHANGED
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: polyamory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.6.
|
5
|
+
version: 0.6.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Mislav Marohnić
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-09 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A cli runner for all tests regardless of framework
|
15
15
|
email: mislav.marohnic@gmail.com
|
@@ -19,6 +19,7 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- bin/polyamory
|
22
|
+
- lib/polyamory/bats.rb
|
22
23
|
- lib/polyamory/command.rb
|
23
24
|
- lib/polyamory/cucumber.rb
|
24
25
|
- lib/polyamory/rooted_pathname.rb
|