spec-bench 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +6 -0
- data/LICENSE +20 -0
- data/README.markdown +21 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/bench.rb +25 -0
- data/lib/bench/runs_in.rb +31 -0
- data/spec/bench_spec.rb +16 -0
- data/spec/spec_helper.rb +9 -0
- metadata +84 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Ryan Bigg
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# spec-bench
|
2
|
+
|
3
|
+
spec-bench is (at the moment) a one-trick dog.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
To use this, install it as a gem:
|
8
|
+
|
9
|
+
gem install spec-bench
|
10
|
+
|
11
|
+
Add this in your _spec/spec\_helper.rb_ file as an additional matcher to your config block:
|
12
|
+
|
13
|
+
config.include(Bench::Matchers)
|
14
|
+
|
15
|
+
You're good to go!
|
16
|
+
|
17
|
+
## `run_in`
|
18
|
+
|
19
|
+
lambda { Post.performant_task }.should run_in(3.5.seconds)
|
20
|
+
|
21
|
+
Here we call `.should` on a `Proc` object and pass it `run_in`. This runs the given `Proc`, benchmarking how long it took. If this was longer than the given time it will error, meaning your `performant_task` isn't quite as performant as you thought.
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "spec-bench"
|
8
|
+
gem.summary = %Q{Benchmarks your code through RSpec automated testing}
|
9
|
+
gem.description = %Q{Benchmarks your code through RSpec automated testing}
|
10
|
+
gem.email = "ryan@getup.org.au"
|
11
|
+
gem.homepage = "http://github.com/radar/spec-bench"
|
12
|
+
gem.authors = ["Ryan Bigg"]
|
13
|
+
gem.add_development_dependency "rspec"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
Jeweler::GemcutterTasks.new
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
if File.exist?('VERSION')
|
41
|
+
version = File.read('VERSION')
|
42
|
+
else
|
43
|
+
version = ""
|
44
|
+
end
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "bench #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/lib/bench.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'rspec'
|
3
|
+
require 'active_support/core_ext/numeric/time'
|
4
|
+
require 'active_support/duration'
|
5
|
+
require 'active_support/vendor'
|
6
|
+
|
7
|
+
class Numeric #:nodoc:
|
8
|
+
include ActiveSupport::CoreExtensions::Numeric::Time
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'active_support/core_ext/array/conversions'
|
12
|
+
|
13
|
+
class Array #:nodoc:
|
14
|
+
include ActiveSupport::CoreExtensions::Array::Conversions
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'active_support/core_ext/hash/keys'
|
18
|
+
require 'active_support/core_ext/hash/reverse_merge'
|
19
|
+
|
20
|
+
class Hash #:nodoc:
|
21
|
+
include ActiveSupport::CoreExtensions::Hash::Keys
|
22
|
+
include ActiveSupport::CoreExtensions::Hash::ReverseMerge
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'bench/runs_in'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Bench
|
2
|
+
module Matchers
|
3
|
+
class RunsIn #:nodoc:
|
4
|
+
def initialize(receiver=nil, &block)
|
5
|
+
@receiver = receiver
|
6
|
+
# Placeholder
|
7
|
+
end
|
8
|
+
|
9
|
+
def matches?(event_proc)
|
10
|
+
raise_block_syntax_error if block_given?
|
11
|
+
|
12
|
+
@before = Time.now
|
13
|
+
event_proc.call
|
14
|
+
@after = Time.now
|
15
|
+
|
16
|
+
@distance = @after - @before
|
17
|
+
return @distance < @receiver
|
18
|
+
end
|
19
|
+
|
20
|
+
def failure_message
|
21
|
+
duration = ActiveSupport::Duration.new(1, [[:seconds, @distance]])
|
22
|
+
"Expected call to run in #{@receiver.inspect}, actually ran in #{duration.inspect}."
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
def run_in(receiver=nil, &block)
|
28
|
+
Matchers::RunsIn.new(receiver, &block)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/bench_spec.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Bench" do
|
4
|
+
it "runs in under 2 seconds" do
|
5
|
+
lambda { sleep(0.1) }.should run_in(0.2.seconds)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "fails to run in under 2.5 seconds" do
|
9
|
+
lambda { sleep(0.2) }.should_not run_in(0.1.seconds)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "intentionally fails" do
|
13
|
+
block = lambda { sleep(0.2) }
|
14
|
+
message = lambda { block.should run_in(0.1.seconds) }.should raise_error(Spec::Expectations::ExpectationNotMetError)
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spec-bench
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 0.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Ryan Bigg
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-05 00:00:00 +11:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
32
|
+
description: Benchmarks your code through RSpec automated testing
|
33
|
+
email: ryan@getup.org.au
|
34
|
+
executables: []
|
35
|
+
|
36
|
+
extensions: []
|
37
|
+
|
38
|
+
extra_rdoc_files:
|
39
|
+
- LICENSE
|
40
|
+
- README.markdown
|
41
|
+
files:
|
42
|
+
- .document
|
43
|
+
- .gitignore
|
44
|
+
- LICENSE
|
45
|
+
- README.markdown
|
46
|
+
- Rakefile
|
47
|
+
- VERSION
|
48
|
+
- lib/bench.rb
|
49
|
+
- lib/bench/runs_in.rb
|
50
|
+
- spec/bench_spec.rb
|
51
|
+
- spec/spec_helper.rb
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://github.com/radar/spec-bench
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options:
|
58
|
+
- --charset=UTF-8
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.3.6
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: Benchmarks your code through RSpec automated testing
|
82
|
+
test_files:
|
83
|
+
- spec/bench_spec.rb
|
84
|
+
- spec/spec_helper.rb
|