hot_or_not 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/hot_or_not +12 -4
- data/lib/hot_or_not/comparison_result.rb +2 -0
- data/lib/hot_or_not/runner.rb +11 -1
- data/test/runner_test.rb +94 -21
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.9
|
data/bin/hot_or_not
CHANGED
@@ -5,16 +5,21 @@ require File.dirname(__FILE__) + '/../lib/hot_or_not'
|
|
5
5
|
require 'optparse'
|
6
6
|
|
7
7
|
defaults = {
|
8
|
-
:output_directory => 'test_results'
|
8
|
+
:output_directory => 'test_results',
|
9
|
+
:test_names => :all
|
9
10
|
}
|
10
11
|
|
11
12
|
options = {}
|
12
13
|
parser = ::OptionParser.new do |opts|
|
13
14
|
opts.banner = "Usage: hot_or_not [options] URL_FILE"
|
14
|
-
opts.on("-o", "--output-dir", "Ouput directory. DEFAULT: #{defaults[:output_directory]}") do |d|
|
15
|
+
opts.on("-o", "--output-dir [DIRECTORY]", "Ouput base directory. DEFAULT: #{defaults[:output_directory]}") do |d|
|
15
16
|
options[:output_directory] = d
|
16
17
|
end
|
17
18
|
|
19
|
+
opts.on('-n', '--name [NAMES]', "Test names to run. DEFAULT: all") do |test_names|
|
20
|
+
options[:test_names] = test_names.split(',')
|
21
|
+
end
|
22
|
+
|
18
23
|
opts.on_tail("--example-file", "Output contents of example file") do
|
19
24
|
puts
|
20
25
|
puts File.read(File.dirname(__FILE__) + '/../test/data/simple_urls.yml')
|
@@ -43,5 +48,8 @@ unless File.exists? yaml_file
|
|
43
48
|
exit
|
44
49
|
end
|
45
50
|
|
46
|
-
|
47
|
-
|
51
|
+
suite_name = File.basename(yaml_file).gsub('.yml', '').gsub('.erb', '')
|
52
|
+
output_dir = File.join options[:output_directory], suite_name
|
53
|
+
|
54
|
+
announcer = HotOrNot::ConsoleAnnouncer.new output_dir
|
55
|
+
HotOrNot::Runner.run_from(yaml_file, announcer).run! options[:test_names]
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module HotOrNot
|
2
2
|
class ComparisonResult
|
3
|
+
extend Forwardable
|
3
4
|
|
4
5
|
class << self
|
5
6
|
def for(compare_url)
|
@@ -10,6 +11,7 @@ module HotOrNot
|
|
10
11
|
end
|
11
12
|
|
12
13
|
attr_reader :message
|
14
|
+
def_delegators :@compare_url, :short_name
|
13
15
|
|
14
16
|
def initialize(compare_url, side_a_results, side_b_results)
|
15
17
|
@compare_url, @side_a_results, @side_b_results = compare_url, side_a_results, side_b_results
|
data/lib/hot_or_not/runner.rb
CHANGED
@@ -8,9 +8,11 @@ module HotOrNot
|
|
8
8
|
@urls, @announcer = urls, announcer
|
9
9
|
end
|
10
10
|
|
11
|
-
def run!
|
11
|
+
def run!(to_run = :all)
|
12
|
+
@to_run = to_run
|
12
13
|
@announcer.starting
|
13
14
|
@urls.each do |url|
|
15
|
+
next unless should_run? url
|
14
16
|
result = ComparisonResult.for url
|
15
17
|
if result.success?
|
16
18
|
@announcer.announce_success result
|
@@ -22,5 +24,13 @@ module HotOrNot
|
|
22
24
|
end
|
23
25
|
@announcer.ending
|
24
26
|
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def should_run?(url)
|
30
|
+
return true if @to_run == :all
|
31
|
+
Array(@to_run).any? do |to_run|
|
32
|
+
url.full_name == to_run || url.short_name == to_run
|
33
|
+
end
|
34
|
+
end
|
25
35
|
end
|
26
36
|
end
|
data/test/runner_test.rb
CHANGED
@@ -2,39 +2,81 @@ require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
|
|
2
2
|
|
3
3
|
module HotOrNot
|
4
4
|
class RunnerTest < Test::Unit::TestCase
|
5
|
+
|
5
6
|
def initialize(*args)
|
6
7
|
@announcer = Class.new do
|
7
8
|
include Announcer
|
8
9
|
|
9
10
|
attr_reader :messages
|
10
11
|
def initialize
|
11
|
-
@messages = {}
|
12
|
+
@messages = Hash.new { |hash, key| hash[key] = [] }
|
12
13
|
end
|
13
14
|
|
14
15
|
def starting
|
15
|
-
@messages[:starting]
|
16
|
+
@messages[:starting] << :starting
|
16
17
|
end
|
17
18
|
|
18
19
|
def ending
|
19
|
-
@messages[:ending]
|
20
|
+
@messages[:ending] << :ending
|
20
21
|
end
|
21
22
|
|
22
23
|
def announce_success(result)
|
23
|
-
@messages[:success]
|
24
|
+
@messages[:success] << result.short_name
|
24
25
|
end
|
25
26
|
|
26
27
|
def announce_failure(result)
|
27
|
-
@messages[:failure]
|
28
|
+
@messages[:failure] << result.short_name
|
28
29
|
end
|
29
30
|
|
30
31
|
def announce_error(result)
|
31
|
-
@messages[:error]
|
32
|
+
@messages[:error] << result.short_name
|
32
33
|
end
|
33
34
|
end.new
|
34
35
|
|
35
36
|
super
|
36
37
|
end
|
37
38
|
|
39
|
+
context "running" do
|
40
|
+
|
41
|
+
context "all" do
|
42
|
+
setup do
|
43
|
+
@url1 = mock_compare_url('Foo', '/api/foo', 'foo', 'foo')
|
44
|
+
@url2 = mock_compare_url('Bar', '/api/bar', 'bar', 'bar')
|
45
|
+
@urls = [@url1, @url2]
|
46
|
+
end
|
47
|
+
|
48
|
+
should "if nothing passed in" do
|
49
|
+
Runner.new(@urls, @announcer).run!
|
50
|
+
assert_ran @announcer, @url1.full_name, @url2.full_name
|
51
|
+
end
|
52
|
+
|
53
|
+
should "if :all passed in" do
|
54
|
+
Runner.new(@urls, @announcer).run! :all
|
55
|
+
assert_ran @announcer, @url1.full_name, @url2.full_name
|
56
|
+
end
|
57
|
+
|
58
|
+
should "run all specified tests" do
|
59
|
+
Runner.new(@urls, @announcer).run! @urls.map(&:short_name)
|
60
|
+
assert_ran @announcer, @url1.full_name, @url2.full_name
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "one" do
|
65
|
+
setup do
|
66
|
+
@url1 = mock_compare_url('Foo', '/api/foo', 'foo', 'foo')
|
67
|
+
@url2 = CompareUrl.new('Bar', '/api/bar', 'bar', 'bar')
|
68
|
+
@urls = [@url1, @url2]
|
69
|
+
end
|
70
|
+
|
71
|
+
should "only run specified test" do
|
72
|
+
Runner.new(@urls, @announcer).run! @url1.full_name
|
73
|
+
|
74
|
+
assert_ran @announcer, @url1.full_name
|
75
|
+
assert_not_ran @announcer, @url2.full_name
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
38
80
|
context "successful comparison" do
|
39
81
|
setup do
|
40
82
|
urls = [mock_compare_url('Foo', '/api/foo', 'foo', 'foo')]
|
@@ -42,17 +84,17 @@ module HotOrNot
|
|
42
84
|
end
|
43
85
|
|
44
86
|
should "announce starting" do
|
45
|
-
|
87
|
+
assert_called @announcer, :starting
|
46
88
|
end
|
47
89
|
|
48
90
|
should "announce ending" do
|
49
|
-
|
91
|
+
assert_called @announcer, :ending
|
50
92
|
end
|
51
93
|
|
52
94
|
should "only annouce success" do
|
53
|
-
|
54
|
-
|
55
|
-
|
95
|
+
assert_called @announcer, :success
|
96
|
+
assert_not_called @announcer, :failure
|
97
|
+
assert_not_called @announcer, :error
|
56
98
|
end
|
57
99
|
end
|
58
100
|
|
@@ -63,17 +105,17 @@ module HotOrNot
|
|
63
105
|
end
|
64
106
|
|
65
107
|
should "announce starting" do
|
66
|
-
|
108
|
+
assert_called @announcer, :starting
|
67
109
|
end
|
68
110
|
|
69
111
|
should "announce ending" do
|
70
|
-
|
112
|
+
assert_called @announcer, :ending
|
71
113
|
end
|
72
114
|
|
73
115
|
should "only annouce failure" do
|
74
|
-
|
75
|
-
|
76
|
-
|
116
|
+
assert_called @announcer, :failure
|
117
|
+
assert_not_called @announcer, :success
|
118
|
+
assert_not_called @announcer, :error
|
77
119
|
end
|
78
120
|
end
|
79
121
|
|
@@ -84,19 +126,50 @@ module HotOrNot
|
|
84
126
|
end
|
85
127
|
|
86
128
|
should "announce starting" do
|
87
|
-
|
129
|
+
assert_called @announcer, :starting
|
88
130
|
end
|
89
131
|
|
90
132
|
should "announce ending" do
|
91
|
-
|
133
|
+
assert_called @announcer, :ending
|
92
134
|
end
|
93
135
|
|
94
136
|
should "only annouce error" do
|
95
|
-
|
96
|
-
|
97
|
-
|
137
|
+
assert_called @announcer, :error
|
138
|
+
assert_not_called @announcer, :success
|
139
|
+
assert_not_called @announcer, :failure
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
private
|
144
|
+
def assert_called(announcer, type, times = 1, msg = nil)
|
145
|
+
msg ||= "The #{type} message was not announced #{times} time(s)."
|
146
|
+
assert_equal times, announcer.messages[type.to_sym].count, msg
|
147
|
+
end
|
148
|
+
|
149
|
+
def assert_not_called(announcer, type)
|
150
|
+
assert_called announcer, type, 0, "The #{type} messages was called when it shouldn't have been"
|
151
|
+
end
|
152
|
+
|
153
|
+
def assert_ran(announcer, *tests)
|
154
|
+
tests.each do |test|
|
155
|
+
assert_equal 1, count_results(announcer, test), "Test '#{test}' was not run."
|
98
156
|
end
|
99
157
|
end
|
100
158
|
|
159
|
+
def assert_not_ran(announcer, *tests)
|
160
|
+
tests.each do |test|
|
161
|
+
assert_equal 0, count_results(announcer, test), "Test '#{test}' was run and shouldn't have been."
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def count_results(announcer, test)
|
166
|
+
test_name = test.underscore.gsub(/\s+/, '_')
|
167
|
+
count = 0
|
168
|
+
count += announcer.messages[:success].count { |result_name| result_name == test_name }
|
169
|
+
count += announcer.messages[:failure].count { |result_name| result_name == test_name }
|
170
|
+
count += announcer.messages[:error].count { |result_name| result_name == test_name }
|
171
|
+
count
|
172
|
+
end
|
173
|
+
|
101
174
|
end
|
102
175
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hot_or_not
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 9
|
10
|
+
version: 0.1.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joel Friedman
|