rspec-smart-formatter 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rspec +3 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/README.md +50 -0
- data/Rakefile +7 -0
- data/lib/rspec-smart-formatter.rb +1 -0
- data/lib/rspec/smart/formatter.rb +40 -0
- data/rspec-smart-formatter.gemspec +21 -0
- data/spec/smart-formatter.feature +28 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/step_definitions.rb +40 -0
- metadata +84 -0
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.3@rspec-smart-formatter
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# RSpec Smart Formatter
|
2
|
+
|
3
|
+
RSpec Smart Formatter automatically chooses an appropriate formatter depending on the amount of
|
4
|
+
specs you're running.
|
5
|
+
|
6
|
+
## Why this formatter exists
|
7
|
+
|
8
|
+
This gem is for scratching an itch I have. When I run focussed tests (like, only one file, or only
|
9
|
+
one example group) I want to use the documentation formatter, which gives me a better view of which
|
10
|
+
tests pass and which tests fail.
|
11
|
+
|
12
|
+
When I run a lot of tests, I want something that doesn't fill my entire bash history and just shows
|
13
|
+
the list of specs.
|
14
|
+
|
15
|
+
I like formatters like [Instafail](https://github.com/grosser/rspec-instafail) and
|
16
|
+
[Fuubar](https://github.com/jeffkreeftmeijer/fuubar), which easily handles thousands of tests,
|
17
|
+
without cluttering your terminal, and showing you the failing specs instantly so you can figure out
|
18
|
+
what went wrong without having to wait for your whole suite to finish.
|
19
|
+
|
20
|
+
I could write `-fd` and `-fp` manually, but I keep forgetting that.
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Add to your gemfile:
|
25
|
+
|
26
|
+
``` ruby
|
27
|
+
group :test do
|
28
|
+
gem 'rspec-smart-formatter', :require => false
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
Run `bundle install`
|
33
|
+
|
34
|
+
|
35
|
+
Add it your `.rspec` file:
|
36
|
+
|
37
|
+
```
|
38
|
+
--format RSpec::Smart::Formatter
|
39
|
+
```
|
40
|
+
|
41
|
+
And you're done!
|
42
|
+
|
43
|
+
## Configuration
|
44
|
+
|
45
|
+
Don't know yet. Still working on it.
|
46
|
+
|
47
|
+
|
48
|
+
## Copyright
|
49
|
+
|
50
|
+
Copyright 2012, Iain Hecker. Released under the MIT License.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rspec/smart/formatter'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rspec/core/formatters/documentation_formatter'
|
2
|
+
require 'rspec/core/formatters/progress_formatter'
|
3
|
+
require 'delegate'
|
4
|
+
|
5
|
+
module RSpec
|
6
|
+
module Smart
|
7
|
+
class Formatter < ::Delegator
|
8
|
+
|
9
|
+
def initialize(*args)
|
10
|
+
@initialize_args = args
|
11
|
+
end
|
12
|
+
|
13
|
+
def start(example_count)
|
14
|
+
@example_count = example_count
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def __getobj__
|
19
|
+
if @example_count <= 20
|
20
|
+
documentation_formatter
|
21
|
+
else
|
22
|
+
progress_formatter
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def __setobj__(obj)
|
27
|
+
raise NotImplementedError.new("The delegated object is calculated automatically, it is not to be set")
|
28
|
+
end
|
29
|
+
|
30
|
+
def documentation_formatter
|
31
|
+
@documentation_formatter ||= RSpec::Core::Formatters::DocumentationFormatter.new(*@initialize_args)
|
32
|
+
end
|
33
|
+
|
34
|
+
def progress_formatter
|
35
|
+
@progress_formatter ||= RSpec::Core::Formatters::ProgressFormatter.new(*@initialize_args)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "rspec-smart-formatter"
|
5
|
+
s.version = '0.0.1'
|
6
|
+
s.authors = ["iain"]
|
7
|
+
s.email = ["iain@iain.nl"]
|
8
|
+
s.homepage = ""
|
9
|
+
s.summary = %q{Automatically chooses a handy formatter}
|
10
|
+
s.description = %q{When you run individual specs, I want to see documentation output, because it shows better which specs fails. But when I run all my specs I want something like progress or Fuubar.}
|
11
|
+
|
12
|
+
s.rubyforge_project = "rspec-smart-formatter"
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_development_dependency "turnip"
|
20
|
+
s.add_runtime_dependency "rspec-core", "~> 2.0"
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Feature: Smart Formatter
|
2
|
+
|
3
|
+
Because I want to save time figuring out which tests have failed,
|
4
|
+
I can specify to always use the smart formatter
|
5
|
+
So it will choose the best possible formatter for me.
|
6
|
+
|
7
|
+
Background:
|
8
|
+
Given I have installed the smart formatter
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
Scenario: Running only a couple of specs
|
13
|
+
|
14
|
+
With a couple of specs, it's easier to use the documentation formatter.
|
15
|
+
It allowes you to see in relation to other specs, which specs failed.
|
16
|
+
I'm guessing about 20 specs is the maximum for documentation to be readable.
|
17
|
+
|
18
|
+
When I run 20 specs
|
19
|
+
Then I should see the documentation output
|
20
|
+
|
21
|
+
Scenario: Running a lot of specs
|
22
|
+
|
23
|
+
Wit a lot of specs, you'd want a shorter output.
|
24
|
+
Since we cannot be sure you have something fancy like Fuubar installed, it will use progress
|
25
|
+
|
26
|
+
When I run 100 specs
|
27
|
+
Then I should see the progress output
|
28
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require 'step_definitions'
|
3
|
+
|
4
|
+
TEST_PROJECT_DIR = File.expand_path("../../tmp/test_project", __FILE__)
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
|
8
|
+
config.around :each do |example|
|
9
|
+
FileUtils.rm_r TEST_PROJECT_DIR if File.exist?(TEST_PROJECT_DIR)
|
10
|
+
FileUtils.mkdir_p TEST_PROJECT_DIR
|
11
|
+
Dir.chdir TEST_PROJECT_DIR do
|
12
|
+
example.run
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
step "I have installed the smart formatter" do
|
2
|
+
FileUtils.mkdir_p "spec"
|
3
|
+
File.open(".rspec", "w") do |f|
|
4
|
+
f << "--format RSpec::Smart::Formatter\n"
|
5
|
+
f << "-I #{File.expand_path('../../lib')}\n"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
step "I run :count specs" do |count|
|
10
|
+
File.open("spec/sample_spec.rb", "w") do |f|
|
11
|
+
f << "describe 'something' do"
|
12
|
+
count.times do |i|
|
13
|
+
f << " it 'the description of the specs' do; end\n\n"
|
14
|
+
end
|
15
|
+
f << "end"
|
16
|
+
end
|
17
|
+
@stdout = ""
|
18
|
+
@stderr = ""
|
19
|
+
Open3.popen3("rspec") do |stdin, stdout, stderr, thr|
|
20
|
+
@stdout << stdout.read
|
21
|
+
@stderr << stderr.read
|
22
|
+
end
|
23
|
+
if @stderr != ""
|
24
|
+
puts @stderr
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
step "I should see the documentation output" do
|
29
|
+
@stdout.should include("the description of the specs")
|
30
|
+
end
|
31
|
+
|
32
|
+
step "I should see the progress output" do
|
33
|
+
@stdout.should include("................")
|
34
|
+
end
|
35
|
+
|
36
|
+
placeholder :count do
|
37
|
+
match /\d+/ do |count|
|
38
|
+
count.to_i
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-smart-formatter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- iain
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: turnip
|
16
|
+
requirement: &2164228640 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2164228640
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec-core
|
27
|
+
requirement: &2164228120 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2164228120
|
36
|
+
description: When you run individual specs, I want to see documentation output, because
|
37
|
+
it shows better which specs fails. But when I run all my specs I want something
|
38
|
+
like progress or Fuubar.
|
39
|
+
email:
|
40
|
+
- iain@iain.nl
|
41
|
+
executables: []
|
42
|
+
extensions: []
|
43
|
+
extra_rdoc_files: []
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- .rspec
|
47
|
+
- .rvmrc
|
48
|
+
- Gemfile
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- lib/rspec-smart-formatter.rb
|
52
|
+
- lib/rspec/smart/formatter.rb
|
53
|
+
- rspec-smart-formatter.gemspec
|
54
|
+
- spec/smart-formatter.feature
|
55
|
+
- spec/spec_helper.rb
|
56
|
+
- spec/step_definitions.rb
|
57
|
+
homepage: ''
|
58
|
+
licenses: []
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project: rspec-smart-formatter
|
77
|
+
rubygems_version: 1.8.10
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Automatically chooses a handy formatter
|
81
|
+
test_files:
|
82
|
+
- spec/smart-formatter.feature
|
83
|
+
- spec/spec_helper.rb
|
84
|
+
- spec/step_definitions.rb
|