rapido 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .idea
7
+ .rvmrc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rapido.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Justin Ricaurte
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Rapido
2
+
3
+ Slow tests suck, and rapido makes them faster so you can make more descriptive tests! Rapido extends Rspec so that you can have specs that run fast and are also very descriptive. Use the ex method like it, but instead of creating a new context, it will run in the existing context.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rapido'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rapido
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,10 @@
1
+ require "rapido/version"
2
+ require 'rspec/core'
3
+
4
+ module Rapido
5
+ # Your code goes here...
6
+ end
7
+
8
+ require 'rapido/rspec_ext/rspec'
9
+ require 'rapido/rspec_ext/core/example'
10
+ require 'rapido/rspec_ext/core/example_group'
@@ -0,0 +1,25 @@
1
+ RSpec::Core::Example.class_eval do
2
+
3
+ def rapido_run(example_group_instance, reporter)
4
+ @example_group_instance = example_group_instance
5
+ @example_group_instance.example = self
6
+
7
+ start(reporter)
8
+ begin
9
+ @example_group_instance.instance_eval(&@example_block)
10
+ rescue RSpec::Core::Pending::PendingDeclaredInExample => e
11
+ @pending_declared_in_example = e.message
12
+ rescue Exception => e
13
+ set_exception(e)
14
+ ensure
15
+ begin
16
+ assign_generated_description
17
+ rescue Exception => e
18
+ set_exception(e, "while assigning the example description")
19
+ end
20
+ end unless pending
21
+
22
+ finish(reporter)
23
+ end
24
+
25
+ end
@@ -0,0 +1,80 @@
1
+ RSpec::Core::ExampleGroup.class_eval do
2
+
3
+ class << self
4
+ alias_method :run_examples_without_rapido, :run_examples
5
+ end
6
+
7
+ # @private
8
+ def self.run_examples_with_rapido(reporter)
9
+ if RSpec.rapido_enabled?
10
+ rapido_run_examples(reporter)
11
+ else
12
+ run_examples_without_rapido(reporter)
13
+ end
14
+ end
15
+
16
+ class << self
17
+ alias_method :run_examples, :run_examples_with_rapido
18
+ end
19
+
20
+ def self.rapido_run_examples(reporter)
21
+ instance = new
22
+ set_ivars(instance, before_all_ivars)
23
+
24
+ all_succeeded = true
25
+ ordered_examples = filtered_examples.ordered
26
+ first_example = ordered_examples.first
27
+ counter = 0
28
+ begin
29
+ first_example.instance_variable_set(:"@example_group_instance", instance)
30
+ instance.example = first_example
31
+ first_example.send :with_around_each_hooks do
32
+ begin
33
+ first_example.send :run_before_each
34
+ all_succeeded = ordered_examples.map do |example|
35
+ next if RSpec.wants_to_quit
36
+
37
+ succeeded = example.rapido_run(instance, reporter)
38
+
39
+ counter += 1
40
+ RSpec.wants_to_quit = true if fail_fast? && !succeeded
41
+ succeeded
42
+ end.all?
43
+ rescue Exception => e
44
+ if ordered_examples.size == counter
45
+ rapido_report_exception(e)
46
+ else
47
+ all_succeeded = false
48
+ rapido_set_exceptions(reporter, ordered_examples, counter, e)
49
+ end
50
+ ensure
51
+ first_example.send :run_after_each
52
+ end
53
+ end
54
+ rescue Exception => e
55
+ if ordered_examples.size == counter
56
+ rapido_report_exception(e)
57
+ else
58
+ rapido_report_exception(e)
59
+ all_succeeded = false
60
+ rapido_set_exceptions(reporter, ordered_examples, counter, e)
61
+ end
62
+ end if !first_example.nil?
63
+ all_succeeded
64
+ end
65
+
66
+
67
+ def self.rapido_set_exceptions(reporter, ordered_examples, counter, exception)
68
+ ordered_examples[counter..-1].each do |example|
69
+ example.send(:start, reporter)
70
+ example.set_exception(exception)
71
+ example.send(:finish, reporter)
72
+ end
73
+ end
74
+
75
+ def self.rapido_report_exception(exception)
76
+ puts "Exception in example group: #{exception}"
77
+ exception.backtrace.each{|line| puts " #{line}"}
78
+ end
79
+
80
+ end
@@ -0,0 +1,19 @@
1
+ module RSpec
2
+
3
+ def self.rapido_enabled?
4
+ @rapido_enabled
5
+ end
6
+
7
+ def self.enable_rapido
8
+ puts "Rapido - enabled"
9
+ @rapido_enabled = true
10
+ end
11
+
12
+ def self.disable_rapido
13
+ puts "Rapido - disabled (to enable rapido send RAPIDO=true as an environment parameter with your rspec tests)"
14
+ @rapido_enabled = false
15
+ end
16
+
17
+ end
18
+
19
+ ENV['RAPIDO'] == "true" ? RSpec.enable_rapido : RSpec.disable_rapido
@@ -0,0 +1,3 @@
1
+ module Rapido
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rapido/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rapido"
8
+ spec.version = Rapido::VERSION
9
+ spec.authors = ["Justin Ricaurte"]
10
+ spec.email = ["justin@justinricaurte.com"]
11
+ spec.description = %q{Make descriptive rspec tests fast!}
12
+ spec.summary = %q{As descriptive as lots of "it"'s but without the overhead.}
13
+ spec.homepage = "https://github.com/ricaurte/rapido"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 2.13"
24
+ spec.add_dependency "rspec-core", "~> 2.13"
25
+ end
@@ -0,0 +1,220 @@
1
+ $: << File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..'))
2
+ require 'spec/spec_helper'
3
+
4
+ module RSpec::Core
5
+ describe ExampleGroup do
6
+
7
+ let(:world) { w = World.new; w.stub(filter_manager: filter_manager); w }
8
+ let(:filter_manager) { FilterManager.new }
9
+
10
+ let(:example_group) { RSpec::Core::ExampleGroup.describe }
11
+ let(:reporter) { RSpec::Core::Configuration.new.reporter }
12
+
13
+ class RapidlyExceptioning < Exception; end
14
+
15
+ describe ".rapido_run_examples" do
16
+
17
+ context "example group not sent a block" do
18
+
19
+ let(:example_group) do
20
+ RSpec::Core::ExampleGroup.describe
21
+ end
22
+
23
+ before do
24
+ example_group.rapido_run_examples(reporter)
25
+ end
26
+
27
+ it { example_group.examples.count.should == 0 }
28
+
29
+ end
30
+
31
+ context "example group has no examples in a block" do
32
+
33
+ let(:example_group) do
34
+ RSpec::Core::ExampleGroup.describe do
35
+ end
36
+ end
37
+
38
+ before do
39
+ example_group.rapido_run_examples(reporter)
40
+ end
41
+
42
+ it { example_group.examples.count.should == 0 }
43
+
44
+ end
45
+
46
+ context "example group has examples without blocks" do
47
+
48
+ let(:example_group) do
49
+ RSpec::Core::ExampleGroup.describe do
50
+ it "should be pending"
51
+ it "should also be pending"
52
+ end
53
+ end
54
+
55
+ before do
56
+ example_group.rapido_run_examples(reporter)
57
+ end
58
+
59
+ it { example_group.examples.count.should == 2 }
60
+ it { example_group.examples[0].exception.should == nil }
61
+ it { example_group.examples[0].pending.should == "Not yet implemented" }
62
+ it { example_group.examples[1].exception.should == nil }
63
+ it { example_group.examples[1].pending.should == "Not yet implemented" }
64
+
65
+ end
66
+
67
+
68
+ context "example group has simple examples" do
69
+
70
+ let(:example_group) do
71
+ RSpec::Core::ExampleGroup.describe do
72
+ it { (1 + 5).should == 6 }
73
+ it { (1 + 6).should == 7 }
74
+ end
75
+ end
76
+
77
+ before do
78
+ example_group.rapido_run_examples(reporter)
79
+ end
80
+
81
+ it { example_group.examples[0].exception.should == nil }
82
+ it { example_group.examples[1].exception.should == nil }
83
+
84
+ end
85
+
86
+ context "an example in an example group modifies the instance variables" do
87
+
88
+ let(:example_group) do
89
+ RSpec::Core::ExampleGroup.describe do
90
+
91
+ before do
92
+ @name = "chimichunga"
93
+ end
94
+
95
+ it { @name.should == "chimichunga" }
96
+ it { @name = "hey dude" }
97
+ it { @name.should == "chimichunga" }
98
+
99
+ end
100
+ end
101
+
102
+ before do
103
+ example_group.rapido_run_examples(reporter)
104
+ end
105
+
106
+ it { example_group.filtered_examples[0].exception.should == nil }
107
+ it { example_group.filtered_examples[1].exception.should == nil }
108
+ it { example_group.filtered_examples[2].exception.should_not == nil }
109
+ it { example_group.filtered_examples[2].exception.class.name.should == "RSpec::Expectations::ExpectationNotMetError" }
110
+ it { example_group.filtered_examples[2].exception.to_s.should == "expected: \"chimichunga\"\n got: \"hey dude\" (using ==)" }
111
+
112
+ end
113
+
114
+ context "check before each" do
115
+
116
+ let(:example_group) do
117
+ RSpec::Core::ExampleGroup.describe do
118
+ let!(:count) do
119
+ @count ||= 0
120
+ @count += 1
121
+ end
122
+
123
+ it { @count.should == 1 }
124
+ it { @count.should == 1 }
125
+ it { @count.should == 1 }
126
+
127
+ end
128
+ end
129
+
130
+ before do
131
+ example_group.rapido_run_examples(reporter)
132
+ end
133
+
134
+ it { example_group.filtered_examples[0].exception.should == nil }
135
+ it { example_group.filtered_examples[1].exception.should == nil }
136
+ it { example_group.filtered_examples[2].exception.should == nil }
137
+
138
+ end
139
+
140
+ context "parent has before's" do
141
+
142
+ it "should run the parent before's"
143
+
144
+ end
145
+
146
+ context "after each" do
147
+
148
+ it "should only be run once"
149
+
150
+ end
151
+
152
+ context "an exception occurs before the examples run" do
153
+
154
+ let(:example_group) do
155
+ group = RSpec::Core::ExampleGroup.describe do
156
+
157
+ before do
158
+ raise RapidlyExceptioning
159
+ end
160
+
161
+ it { 1.should == 1 }
162
+ it { 2.should == 2 }
163
+
164
+ end
165
+ group.stub(world: world)
166
+ group.register
167
+ world.instance_variable_get(:"@filtered_examples")[group] = begin
168
+ examples = group.examples.dup
169
+ examples = world.filter_manager.prune(examples)
170
+ examples.uniq
171
+ examples.extend(Extensions::Ordered::Examples)
172
+ end
173
+ group
174
+ end
175
+
176
+ before do
177
+ example_group.rapido_run_examples(reporter)
178
+ end
179
+
180
+ it "should give the first example the exception" do
181
+ example_group.examples.first.exception.class.should == RapidlyExceptioning
182
+ end
183
+
184
+ it "should give the second example the exception" do
185
+ example_group.examples[1].exception.class.should == RapidlyExceptioning
186
+ end
187
+
188
+ it "should give both the same exception" do
189
+ example_group.examples.first.exception.should == example_group.examples[1].exception
190
+ end
191
+
192
+ end
193
+
194
+ context "retrieving meta data in the before" do
195
+
196
+ let(:example_group) do
197
+ RSpec::Core::ExampleGroup.describe do
198
+
199
+ before do
200
+ @metadata = example.metadata
201
+ end
202
+
203
+ it("hello!", meta: :stuff) { @metadata[:meta].should == :stuff }
204
+
205
+ end
206
+ end
207
+
208
+ before do
209
+ example_group.rapido_run_examples(reporter)
210
+ end
211
+
212
+ it { example_group.filtered_examples[0].exception.should == nil }
213
+
214
+ end
215
+
216
+ end
217
+
218
+ end
219
+
220
+ end
@@ -0,0 +1,12 @@
1
+ $: << File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..'))
2
+ require "spec/spec_helper"
3
+
4
+ describe RSpec::Core::Example do
5
+
6
+ describe "#rapido_run" do
7
+
8
+ let(:example) { RSpec::Core::Example.new }
9
+
10
+ end
11
+
12
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'rapido' # and any other gems you need
5
+
6
+ RSpec.configure do |config|
7
+ # some (optional) config here
8
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rapido
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Justin Ricaurte
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.13'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.13'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec-core
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.13'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.13'
78
+ description: Make descriptive rspec tests fast!
79
+ email:
80
+ - justin@justinricaurte.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .rspec
87
+ - .rvmrc
88
+ - Gemfile
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
92
+ - lib/rapido.rb
93
+ - lib/rapido/rspec_ext/core/example.rb
94
+ - lib/rapido/rspec_ext/core/example_group.rb
95
+ - lib/rapido/rspec_ext/rspec.rb
96
+ - lib/rapido/version.rb
97
+ - rapido.gemspec
98
+ - spec/lib/rapido/rspec_ext/core/example_group_spec.rb
99
+ - spec/lib/rapido/rspec_ext/core/example_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: https://github.com/ricaurte/rapido
102
+ licenses:
103
+ - MIT
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 1.8.24
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: As descriptive as lots of "it"'s but without the overhead.
126
+ test_files:
127
+ - spec/lib/rapido/rspec_ext/core/example_group_spec.rb
128
+ - spec/lib/rapido/rspec_ext/core/example_spec.rb
129
+ - spec/spec_helper.rb