rspec-smart-formatter 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec CHANGED
@@ -1,3 +1,4 @@
1
1
  --color
2
+ --order rand
2
3
  --format RSpec::Smart::Formatter
3
4
  -r turnip
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ script: rspec
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - ruby-head
7
+ - rbx-2.0
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ ## 0.0.4 (unreleased)
4
+
5
+ * ...
6
+
7
+ ## 0.0.3 (2012-01-07)
8
+
9
+ * Add Fuubar support
10
+
11
+ ## 0.0.2 (2012-01-07)
12
+
13
+ * Bugfix, making sure that `@example_count` is an integer
14
+
15
+ ## 0.0.1 (2012-01-06)
16
+
17
+ * Initial version
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # RSpec Smart Formatter
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/iain/rspec-smart-formatter.png)](http://travis-ci.org/iain/rspec-smart-formatter)
4
+
3
5
  RSpec Smart Formatter automatically chooses an appropriate formatter depending on the amount of
4
6
  specs you're running.
5
7
 
8
+
6
9
  ## Why this formatter exists
7
10
 
8
11
  This gem is for scratching an itch I have. When I run focussed tests (like, only one file, or only
@@ -19,7 +22,8 @@ what went wrong without having to wait for your whole suite to finish.
19
22
 
20
23
  I could write `-fd` and `-fp` manually, but I keep forgetting that.
21
24
 
22
- ## Usage
25
+
26
+ ## Installation
23
27
 
24
28
  Add to your gemfile:
25
29
 
@@ -40,11 +44,34 @@ Add it your `.rspec` file:
40
44
 
41
45
  And you're done!
42
46
 
47
+ ## Usage
48
+
49
+ Just run RSpec [as you normally would](https://www.relishapp.com/rspec/rspec-core/docs/command-line).
50
+
51
+ For explaination on how the smart formatter works, [see this
52
+ feature](https://github.com/iain/rspec-smart-formatter/blob/master/spec/features/usage.feature).
53
+
54
+
55
+
43
56
  ## Configuration
44
57
 
45
58
  Don't know yet. Still working on it.
46
59
 
47
60
 
61
+ ## Development
62
+
63
+ To run the specs of rspec-smart-formatter itself:
64
+
65
+ ```
66
+ bundle install
67
+ rspec
68
+ ```
69
+
70
+ PS. Don't run with `bundle exec`.
71
+
72
+ Pull requests are welcome.
73
+
74
+
48
75
  ## Copyright
49
76
 
50
77
  Copyright 2012, Iain Hecker. Released under the MIT License.
data/Rakefile CHANGED
@@ -1,7 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
3
  task :spec do
4
- system "bundle exec rspec"
4
+ status = system "rspec"
5
+ exit status
5
6
  end
6
7
 
7
8
  task :default => :spec
@@ -17,23 +17,44 @@ module RSpec
17
17
  end
18
18
 
19
19
  def __getobj__
20
- if @example_count <= 20
21
- documentation_formatter
20
+ choose_formatter
21
+ end
22
+
23
+ def __setobj__(obj)
24
+ raise "Nothing to set here"
25
+ end
26
+
27
+ private
28
+
29
+ def choose_formatter
30
+ if few_specs?
31
+ formatter_for_fewer_specs
22
32
  else
23
- progress_formatter
33
+ formatter_for_more_specs
24
34
  end
25
35
  end
26
36
 
27
- def __setobj__(obj)
28
- raise NotImplementedError.new("The delegated object is calculated automatically, it is not to be set")
37
+ def few_specs?
38
+ @example_count <= 20
39
+ end
40
+
41
+ def formatter_for_fewer_specs
42
+ formatter RSpec::Core::Formatters::DocumentationFormatter
43
+ end
44
+
45
+ def formatter_for_more_specs
46
+ require 'fuubar'
47
+ formatter Fuubar
48
+ rescue LoadError
49
+ formatter RSpec::Core::Formatters::ProgressFormatter
29
50
  end
30
51
 
31
- def documentation_formatter
32
- @documentation_formatter ||= RSpec::Core::Formatters::DocumentationFormatter.new(*@initialize_args)
52
+ def formatter(formatter)
53
+ formatters[formatter] ||= formatter.new(*@initialize_args)
33
54
  end
34
55
 
35
- def progress_formatter
36
- @progress_formatter ||= RSpec::Core::Formatters::ProgressFormatter.new(*@initialize_args)
56
+ def formatters
57
+ @formatters ||= {}
37
58
  end
38
59
 
39
60
  end
@@ -2,10 +2,10 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "rspec-smart-formatter"
5
- s.version = '0.0.2'
5
+ s.version = '0.0.3'
6
6
  s.authors = ["iain"]
7
7
  s.email = ["iain@iain.nl"]
8
- s.homepage = ""
8
+ s.homepage = "https://github.com/iain/rspec-smart-formatter"
9
9
  s.summary = %q{Automatically chooses a handy formatter}
10
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
11
 
@@ -17,5 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.require_paths = ["lib"]
18
18
 
19
19
  s.add_development_dependency "turnip"
20
+ s.add_development_dependency "fuubar"
21
+ s.add_development_dependency "rake"
20
22
  s.add_runtime_dependency "rspec-core", "~> 2.0"
21
23
  end
@@ -1,10 +1,14 @@
1
- Feature: Smart Formatter
1
+ Feature: Usage
2
2
 
3
3
  Because I want to save time figuring out which tests have failed,
4
4
  I can specify to always use the smart formatter
5
5
  So it will choose the best possible formatter for me.
6
6
 
7
7
  Background:
8
+
9
+ To install the smart formatter, add it to your Gemfile
10
+ and add it to your '.rspec' file.
11
+
8
12
  Given I have installed the smart formatter
9
13
 
10
14
 
@@ -15,14 +19,24 @@ Feature: Smart Formatter
15
19
  It allowes you to see in relation to other specs, which specs failed.
16
20
  I'm guessing about 20 specs is the maximum for documentation to be readable.
17
21
 
18
- When I run 20 specs
22
+ When I run only a couple of specs
19
23
  Then I should see the documentation output
20
24
 
21
25
  Scenario: Running a lot of specs
22
26
 
23
27
  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
28
+ Since we cannot be sure you have something fancy like Fuubar installed,
29
+ it will use the progress formatter.
25
30
 
26
- When I run 100 specs
31
+ Given I don't have any special formatters installed
32
+ When I run a lot of specs
27
33
  Then I should see the progress output
28
34
 
35
+
36
+ Scenario: With Fuubar installed
37
+
38
+ If you have Fuubar installed, this will be preferred over the progress formatter
39
+
40
+ Given I have installed Fuubar
41
+ When I run a lot of specs
42
+ Then I should see the Fuubar output
@@ -0,0 +1,43 @@
1
+ module HelperMethods
2
+
3
+ def create_specs(count = 1)
4
+ create_file "spec/sample_spec.rb" do |f|
5
+ f.puts "describe 'something' do"
6
+ count.times do |i|
7
+ f.puts " it 'the description of the specs' do; end"
8
+ end
9
+ f.puts "end"
10
+ end
11
+ end
12
+
13
+ def create_rspec_config
14
+ create_file '.rspec' do |f|
15
+ f.puts "--format RSpec::Smart::Formatter"
16
+ f.puts "-I #{File.join(PROJECT_DIR, 'lib')}"
17
+ end
18
+ end
19
+
20
+ def run_specs
21
+ run_command "rspec"
22
+ end
23
+
24
+ def run_command(command)
25
+ @stdout ||= ""
26
+ @stderr = ""
27
+ Open3.popen3(command) do |stdin, stdout, stderr, thr|
28
+ @stdout << stdout.read
29
+ @stderr << stderr.read
30
+ end
31
+ if @stderr != ""
32
+ puts @stderr
33
+ end
34
+ end
35
+
36
+ def create_file(filename)
37
+ FileUtils.mkdir_p File.dirname(filename)
38
+ File.open filename, 'w' do |f|
39
+ yield f
40
+ end
41
+ end
42
+
43
+ end
@@ -1,16 +1,19 @@
1
+ PROJECT_DIR = File.expand_path('../../', __FILE__)
2
+ TEST_PROJECT_DIR = File.expand_path("tmp/test_project", PROJECT_DIR)
3
+
1
4
  require 'open3'
2
5
  require 'step_definitions'
3
-
4
- TEST_PROJECT_DIR = File.expand_path("../../tmp/test_project", __FILE__)
6
+ require 'helper_methods'
5
7
 
6
8
  RSpec.configure do |config|
7
9
 
8
10
  config.around :each do |example|
9
- FileUtils.rm_r TEST_PROJECT_DIR if File.exist?(TEST_PROJECT_DIR)
10
11
  FileUtils.mkdir_p TEST_PROJECT_DIR
11
12
  Dir.chdir TEST_PROJECT_DIR do
12
13
  example.run
13
14
  end
14
15
  end
15
16
 
17
+ config.include HelperMethods
18
+
16
19
  end
@@ -1,28 +1,23 @@
1
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
2
+ create_rspec_config
7
3
  end
8
4
 
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
5
+ step "I don't have any special formatters installed" do
6
+ run_command "gem uninstall fuubar"
7
+ end
8
+
9
+ step "I have installed Fuubar" do
10
+ run_command "gem install fuubar"
11
+ end
12
+
13
+ step "I run only a couple of specs" do
14
+ create_specs 20
15
+ run_specs
16
+ end
17
+
18
+ step "I run a lot of specs" do
19
+ create_specs 21
20
+ run_specs
26
21
  end
27
22
 
28
23
  step "I should see the documentation output" do
@@ -33,8 +28,6 @@ step "I should see the progress output" do
33
28
  @stdout.should include("................")
34
29
  end
35
30
 
36
- placeholder :count do
37
- match /\d+/ do |count|
38
- count.to_i
39
- end
31
+ step 'I should see the Fuubar output' do
32
+ @stdout.should include("100% |=======")
40
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-smart-formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: turnip
16
- requirement: &2164228640 !ruby/object:Gem::Requirement
16
+ requirement: &2170952360 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,32 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2164228640
24
+ version_requirements: *2170952360
25
+ - !ruby/object:Gem::Dependency
26
+ name: fuubar
27
+ requirement: &2170951920 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2170951920
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &2170951500 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2170951500
25
47
  - !ruby/object:Gem::Dependency
26
48
  name: rspec-core
27
- requirement: &2164228120 !ruby/object:Gem::Requirement
49
+ requirement: &2170951000 !ruby/object:Gem::Requirement
28
50
  none: false
29
51
  requirements:
30
52
  - - ~>
@@ -32,7 +54,7 @@ dependencies:
32
54
  version: '2.0'
33
55
  type: :runtime
34
56
  prerelease: false
35
- version_requirements: *2164228120
57
+ version_requirements: *2170951000
36
58
  description: When you run individual specs, I want to see documentation output, because
37
59
  it shows better which specs fails. But when I run all my specs I want something
38
60
  like progress or Fuubar.
@@ -45,16 +67,19 @@ files:
45
67
  - .gitignore
46
68
  - .rspec
47
69
  - .rvmrc
70
+ - .travis.yml
71
+ - CHANGELOG.md
48
72
  - Gemfile
49
73
  - README.md
50
74
  - Rakefile
51
75
  - lib/rspec-smart-formatter.rb
52
76
  - lib/rspec/smart/formatter.rb
53
77
  - rspec-smart-formatter.gemspec
54
- - spec/smart-formatter.feature
78
+ - spec/features/usage.feature
79
+ - spec/helper_methods.rb
55
80
  - spec/spec_helper.rb
56
81
  - spec/step_definitions.rb
57
- homepage: ''
82
+ homepage: https://github.com/iain/rspec-smart-formatter
58
83
  licenses: []
59
84
  post_install_message:
60
85
  rdoc_options: []
@@ -79,6 +104,7 @@ signing_key:
79
104
  specification_version: 3
80
105
  summary: Automatically chooses a handy formatter
81
106
  test_files:
82
- - spec/smart-formatter.feature
107
+ - spec/features/usage.feature
108
+ - spec/helper_methods.rb
83
109
  - spec/spec_helper.rb
84
110
  - spec/step_definitions.rb