rspec-compact-doc-formatter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rspec-compact-doc-formatter.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2012 De Marque inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ Rspec Compact Doc Formatter
2
+ ===============
3
+
4
+ Compact yet descriptive Rspec format.
5
+
6
+ Install
7
+ -------
8
+
9
+ ```
10
+ gem install rspec-compact-doc-formatter
11
+ ```
12
+
13
+ If you want to use this formatter as your default formatter, simply put the options in your .rspec file:
14
+
15
+ ```
16
+ --format RspecCompactDocFormatter
17
+ ```
18
+
19
+ Rails 3
20
+ -------
21
+
22
+ In your Gemfile:
23
+
24
+ ```ruby
25
+ group :test do
26
+ gem "rspec-compact-doc-formatter"
27
+ end
28
+ ```
29
+
30
+ Usage
31
+ -----
32
+
33
+ ```
34
+ rspec spec -f RspecCompactDocFormatter
35
+ ```
36
+
37
+ Copyright
38
+ ---------
39
+
40
+ Copyright (c) 2012 De Marque inc. See LICENSE for further details.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,130 @@
1
+ require 'rspec/core/formatters/base_text_formatter'
2
+
3
+ class RspecCompactDocFormatter < RSpec::Core::Formatters::BaseTextFormatter
4
+ def initialize(output)
5
+ super(output)
6
+ @group_level = 0
7
+ end
8
+
9
+ def current_indentation
10
+ ' ' * @group_level
11
+ end
12
+
13
+ def dump_commands_to_rerun_failed_examples
14
+ # Hidden
15
+ end
16
+
17
+ def dump_pending
18
+ # Hidden
19
+ end
20
+
21
+ def example_group_started(example_group)
22
+ super(example_group)
23
+
24
+ description = example_group.description
25
+
26
+ if @group_level == 0
27
+ output_class_name description
28
+ elsif method_name?(description)
29
+ output_prelude_and_method description
30
+ elsif @method_position and @group_level > @method_position
31
+ nil
32
+ else
33
+ @prelude += description + ' '
34
+ end
35
+
36
+ @group_level += 1
37
+ end
38
+
39
+ def example_group_finished(example_group)
40
+ @group_level -= 1
41
+ end
42
+
43
+ def example_passed(example)
44
+ super(example)
45
+ output.puts passed_output(example)
46
+ end
47
+
48
+ def example_pending(example)
49
+ super(example)
50
+ output.puts pending_output(example, example.execution_result[:pending_message])
51
+ end
52
+
53
+ def example_failed(example)
54
+ super(example)
55
+ output.puts failure_output(example, example.execution_result[:exception])
56
+ end
57
+
58
+ def failure_output(example, exception)
59
+ one_liner_description example, 'red'
60
+ end
61
+
62
+ def method_name?(description)
63
+ description[0,1] == '#' or description[0,2] == '::'
64
+ end
65
+
66
+ def next_failure_index
67
+ @next_failure_index ||= 0
68
+ @next_failure_index += 1
69
+ end
70
+
71
+ def one_liner_description(example, color='green')
72
+ content = { :assertion => [], :result => '', :subject => 'it' }
73
+
74
+ if example_group
75
+ example_group.ancestors.reverse.each_with_index do |a, i|
76
+ if i <= @method_position
77
+ nil
78
+ elsif i != @method_position + 1 and a.description[0,4] == 'when'
79
+ content[:assertion] << ", #{a.description}"
80
+ elsif not ['and', 'having', 'when', 'with', 'without'].include? a.description.split(' ')[0] and (i+1) == example_group.ancestors.length
81
+ content[:subject] = a.description
82
+ else
83
+ content[:assertion] << " #{a.description}"
84
+ end
85
+ end
86
+ end
87
+
88
+ content[:subject] = "\e[35m#{content[:subject]}\e[0m "
89
+ content[:subject] = ', ' + content[:subject] if content[:assertion].length > 0
90
+
91
+ content[:result] = example.description.to_s.empty? ? 'FAILED' : example.description
92
+
93
+ return (@method_position == 1 ? ' ' : ' ') + content[:assertion].join + content[:subject] + self.send(color, content[:result])
94
+ end
95
+
96
+ def output_class_name(description)
97
+ output.puts "\n" + description
98
+ @prelude = ''
99
+ end
100
+
101
+ def output_prelude_and_method(description)
102
+ indent_method = @prelude.empty? ? ' ' : ' '
103
+
104
+ if @method_position and @method_position > 1
105
+ if @group_level == 1
106
+ output.puts " "
107
+ else
108
+ indent_method = ' '
109
+ end
110
+ end
111
+
112
+ if not @prelude.empty?
113
+ output.puts "\n " + @prelude
114
+ @prelude = ''
115
+ end
116
+
117
+ output.puts indent_method + cyan(description)
118
+
119
+ @method_position = @group_level
120
+ end
121
+
122
+ def passed_output(example)
123
+ one_liner_description example, 'green'
124
+ end
125
+
126
+ def pending_output(example, message)
127
+ indent = (@method_position and @method_position > 1) ? ' ' : ' '
128
+ yellow("#{indent}#{example.description} (PENDING: #{message})")
129
+ end
130
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-compact-doc-formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sebastien Rosa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &2152995160 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.7
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2152995160
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &2152994280 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2152994280
36
+ description: Compact yet descriptive Rspec format.
37
+ email:
38
+ - sebastien@demarque.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.md
44
+ files:
45
+ - lib/rspec-compact-doc-formatter.rb
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - Gemfile
50
+ homepage: https://github.com/demarque/rspec-compact-doc-formatter
51
+ licenses:
52
+ - MIT
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project: rspec-compact-doc-formatter
71
+ rubygems_version: 1.8.17
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Compact yet descriptive Rspec format.
75
+ test_files: []