rspec-instafail 0.1.9 → 0.2.0
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/lib/rspec/instafail/rspec_1.rb +1 -19
- data/lib/rspec/instafail/rspec_2.rb +6 -19
- data/lib/rspec/instafail/version.rb +1 -1
- data/lib/rspec/instafail.rb +8 -6
- data/spec/instafail_spec.rb +24 -80
- data/spec/rspec_1/a_test.rb +17 -3
- metadata +5 -5
@@ -3,25 +3,7 @@ require 'spec/runner/formatter/progress_bar_formatter'
|
|
3
3
|
module RSpec
|
4
4
|
class Instafail < Spec::Runner::Formatter::ProgressBarFormatter
|
5
5
|
def example_failed(example, counter, failure)
|
6
|
-
|
7
|
-
padding = ' '
|
8
|
-
|
9
|
-
output.puts
|
10
|
-
output.puts red("#{short_padding}#{counter}) #{example_group.description} #{example.description}")
|
11
|
-
output.puts "#{padding}#{red(failure.exception)}"
|
12
|
-
|
13
|
-
[*format_backtrace(failure.exception.backtrace)].each do |backtrace_info|
|
14
|
-
output.puts insta_gray("#{padding}# #{backtrace_info.strip}")
|
15
|
-
end
|
16
|
-
|
17
|
-
output.flush
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
# there is a gray() that returns nil, so we use our own...
|
23
|
-
def insta_gray(text)
|
24
|
-
colour(text, "\e[90m")
|
6
|
+
dump_failure(counter, failure)
|
25
7
|
end
|
26
8
|
end
|
27
9
|
end
|
@@ -3,26 +3,13 @@ require 'rspec/core/formatters/progress_formatter'
|
|
3
3
|
module RSpec
|
4
4
|
class Instafail < RSpec::Core::Formatters::ProgressFormatter
|
5
5
|
def example_failed(example)
|
6
|
-
|
7
|
-
@
|
6
|
+
# do what BaseFormatter#example_failed would do
|
7
|
+
@failed_examples << example
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
padding = ' '
|
14
|
-
output.puts
|
15
|
-
output.puts "#{short_padding}#{@counter}) #{example.full_description}"
|
16
|
-
output.puts "#{padding}#{red("Failure/Error:")} #{red(read_failed_line(exception, example).strip)}"
|
17
|
-
output.puts "#{padding}#{red(exception)}"
|
18
|
-
if exception.respond_to?(:original_exception)
|
19
|
-
output.puts "#{padding}#{red(exception.original_exception)}"
|
20
|
-
end
|
21
|
-
format_backtrace(exception.backtrace, example).each do |backtrace_info|
|
22
|
-
color = defined?(cyan) ? :cyan : :grey # cyan was added in rspec 2.6
|
23
|
-
output.puts send(color, "#{padding}# #{backtrace_info}")
|
24
|
-
end
|
25
|
-
output.flush
|
9
|
+
# do what BaseTextFormatter#dump_failures would do
|
10
|
+
index = failed_examples.size - 1
|
11
|
+
dump_pending_example_fixed(example, index) || dump_failure(example, index)
|
12
|
+
dump_backtrace(example)
|
26
13
|
end
|
27
14
|
end
|
28
15
|
end
|
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'rspec/instafail'
|
2
|
-
RSpec::Instafail::VERSION = '0.
|
2
|
+
RSpec::Instafail::VERSION = '0.2.0'
|
data/lib/rspec/instafail.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
module RSpec
|
2
|
-
# when installed as plugin
|
2
|
+
# Rails 3: when installed as plugin, lib is not in load-path when running tests
|
3
3
|
# https://github.com/grosser/rspec-instafail/pull/3
|
4
|
-
lib = File.dirname(File.dirname(__FILE__))
|
4
|
+
lib = File.expand_path(File.dirname(File.dirname(__FILE__)))
|
5
|
+
$LOAD_PATH << lib unless $LOAD_PATH.include?(lib)
|
6
|
+
|
7
|
+
require 'rspec/instafail/version'
|
8
|
+
|
5
9
|
begin
|
6
|
-
require "
|
10
|
+
require "rspec/instafail/rspec_2"
|
7
11
|
rescue LoadError # try rspec 1
|
8
|
-
require "
|
12
|
+
require "rspec/instafail/rspec_1"
|
9
13
|
end
|
10
|
-
|
11
|
-
require 'rspec/instafail/version'
|
12
14
|
end
|
data/spec/instafail_spec.rb
CHANGED
@@ -1,101 +1,45 @@
|
|
1
1
|
describe 'RSpec::Instafail' do
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
expected: 2,
|
7
|
-
got: 1 \\(using ==\\)
|
8
|
-
# (\\.\\/)?a_test\\.rb:5:(in `block \\(2 levels\\) in <top \\(required\\)>')?
|
9
|
-
\\.\\.\\*\\.
|
2
|
+
context "RSpec 1.x" do
|
3
|
+
before :all do
|
4
|
+
@rspec_result = `cd spec/rspec_1 && bundle exec spec a_test.rb --format RSpec::Instafail`
|
5
|
+
end
|
10
6
|
|
11
|
-
|
7
|
+
before do
|
8
|
+
@output = @rspec_result.dup
|
9
|
+
end
|
12
10
|
|
13
|
-
|
14
|
-
|
11
|
+
it "outputs failures at start of output" do
|
12
|
+
@output.should =~ /^\s*1\)\s*'x fails logically'/m
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
'x a'
|
18
|
-
|
19
|
-
got: 1 \\(using ==\\)
|
20
|
-
(\\./)?a_test\\.rb:5:(in `block \\(2 levels\\) in <top \\(required\\)>')?
|
21
|
-
EXP
|
15
|
+
it 'outputs errors in middle of output' do
|
16
|
+
@output.should =~ /\.\.\*\s*2\)\s*RuntimeError in 'x raises a simple error'/m
|
17
|
+
end
|
22
18
|
|
23
|
-
|
19
|
+
it 'outputs the the ending block' do
|
20
|
+
@output.should =~ /Finished in \d\.\d+ seconds\s*7 examples, 3 failures, 1 pending/
|
21
|
+
end
|
24
22
|
end
|
25
23
|
|
26
24
|
context 'Rspec 2.x' do
|
27
|
-
before
|
25
|
+
before :all do
|
28
26
|
@rspec_result = `cd spec/rspec_2 && bundle exec rspec a_test.rb --require ../../lib/rspec/instafail --format RSpec::Instafail --no-color`
|
29
27
|
end
|
28
|
+
|
30
29
|
before do
|
31
30
|
@output = @rspec_result.dup
|
32
31
|
end
|
33
32
|
|
34
|
-
it "outputs
|
35
|
-
|
36
|
-
1\\) x fails logically
|
37
|
-
Failure\\/Error: 1\\.should == 2
|
38
|
-
expected: 2,
|
39
|
-
got: 1 \\(using ==\\)
|
40
|
-
EXP
|
41
|
-
@output.should =~ Regexp.new(expected, 'x')
|
42
|
-
|
43
|
-
@output.should include('/a_test.rb:5')
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'outputs a simple error' do
|
47
|
-
expected = <<EXP
|
48
|
-
\\.\\.\\*
|
49
|
-
2\\) x raises a simple error
|
50
|
-
Failure\\/Error: raise 'shallow failure'
|
51
|
-
shallow failure
|
52
|
-
EXP
|
53
|
-
@output.should =~ Regexp.new(expected, 'x')
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'outputs an error which responds to original_exception' do
|
57
|
-
expected = <<EXP
|
58
|
-
3\\) x raises a hidden error
|
59
|
-
Failure\\/Error: raise error
|
60
|
-
There is an error in this error\\.
|
61
|
-
There is no error in this error\\.
|
62
|
-
EXP
|
63
|
-
@output.should =~ Regexp.new(expected, 'x')
|
33
|
+
it "outputs failures at start of output" do
|
34
|
+
@output.should =~ /^\s+1\) x fails logically/m
|
64
35
|
end
|
65
|
-
it 'outputs the remaining passing specs and the ending block' do
|
66
|
-
expected = <<EXP
|
67
|
-
\\.
|
68
|
-
|
69
|
-
Pending:
|
70
|
-
x pends
|
71
|
-
# No reason given
|
72
|
-
# \\./a_test\\.rb:14
|
73
36
|
|
74
|
-
|
75
|
-
|
76
|
-
EXP
|
77
|
-
@output.should =~ Regexp.new(expected, 'x')
|
37
|
+
it 'outputs errors in middle of output' do
|
38
|
+
@output.should =~ /\.\.\*\s*2\) x raises a simple error/m
|
78
39
|
end
|
79
40
|
|
80
|
-
it
|
81
|
-
|
82
|
-
expected_output = <<EXP
|
83
|
-
1\\) x a
|
84
|
-
Failure\\/Error: 1\\.should == 2
|
85
|
-
expected: 2,
|
86
|
-
got: 1 \\(using ==\\)
|
87
|
-
# \\./a_test\\.rb:5
|
88
|
-
\\.\\.\\*\\.
|
89
|
-
|
90
|
-
Pending:
|
91
|
-
x d
|
92
|
-
# No reason given
|
93
|
-
# \\./a_test\\.rb:14
|
94
|
-
|
95
|
-
Finished in \\d\\.\\d+ seconds
|
96
|
-
7 examples, 3 failures, 1 pending
|
97
|
-
EXP
|
98
|
-
@output.should =~ Regexp.new(expected_output, 'x')
|
41
|
+
it 'outputs the the ending block' do
|
42
|
+
@output.should =~ /Finished in \d\.\d+ seconds\s*7 examples, 3 failures, 1 pending/
|
99
43
|
end
|
100
44
|
end
|
101
45
|
end
|
data/spec/rspec_1/a_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'rspec', 'instafail'))
|
2
2
|
|
3
3
|
describe 'x' do
|
4
|
-
it '
|
4
|
+
it 'fails logically' do
|
5
5
|
1.should == 2
|
6
6
|
end
|
7
7
|
|
@@ -11,11 +11,25 @@ describe 'x' do
|
|
11
11
|
it 'c' do
|
12
12
|
end
|
13
13
|
|
14
|
-
it '
|
14
|
+
it 'pends' do
|
15
15
|
pending
|
16
16
|
raise
|
17
17
|
end
|
18
18
|
|
19
|
+
it 'raises a simple error' do
|
20
|
+
raise 'shallow failure'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'raises a hidden error' do
|
24
|
+
error = ExceptionWrappingException.new('There is an error in this error.')
|
25
|
+
error.original_exception = RuntimeError.new('There is no error in this error.')
|
26
|
+
raise error
|
27
|
+
end
|
28
|
+
|
19
29
|
it 'e' do
|
20
30
|
end
|
21
|
-
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class ExceptionWrappingException < RuntimeError
|
34
|
+
attr_accessor :original_exception
|
35
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-instafail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Grosser
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-11-21 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|