yard-bench 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: f4b741f7ac917188402ae134a53b8ee9f65a4409
4
+ data.tar.gz: a6db99b9f15facdd66aabd7936176681a0259caa
5
+ !binary "U0hBNTEy":
6
+ metadata.gz: 4c3359d6aaf319af83c779c4998aa438f5ed846b69335a6b6a1082e3eb19450f30cf9f6e2b237cb11d3b004d44f77facc265132ffc54775b2c63e02dc228a894
7
+ data.tar.gz: 22637cfe552421e8bf4d11bb1fd1817a84b27fe7ad2568eb1b6dfc7d589680322935b8e4e7ad1cba61da41b857454afc3330388db48b87b3dd16d94fb8d1a3af
data/.document ADDED
@@ -0,0 +1,11 @@
1
+ # .document is used by rdoc and yard to know how to generate documentation
2
+ # for example, it can be used to control how rdoc gets built when you do `gem install foo`
3
+
4
+ README.rdoc
5
+ lib/**/*.rb
6
+ bin/*
7
+
8
+ # Files below this - are treated as 'extra files', and aren't parsed for ruby code
9
+ -
10
+ features/**/*.feature
11
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yard-bench.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Alexei Matyushkin
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/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alexei Matyushkin
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.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # YARD::Bench
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'yard-bench'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install yard-bench
18
+
19
+ ## Usage
20
+
21
+ Put the following code anywhere within your class:
22
+
23
+ benchmark :func1, :func2
24
+
25
+ or even:
26
+
27
+ class String
28
+ ⌚ :⋅
29
+
30
+ and the benchmarks for the chosen functions will be included in yardoc.
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ require 'bundler/setup'
2
+
3
+ Rake::TaskManager.record_task_metadata = true
4
+
5
+ require 'bueller'
6
+ Bueller::Tasks.new
7
+
8
+ require 'rspec/core/rake_task'
9
+ RSpec::Core::RakeTask.new(:examples) do |examples|
10
+ examples.rspec_opts = '-Ispec'
11
+ end
12
+
13
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
14
+ spec.rspec_opts = '-Ispec'
15
+ spec.rcov = true
16
+ end
17
+
18
+ require 'cucumber/rake/task'
19
+ Cucumber::Rake::Task.new(:features) do |t|
20
+ t.cucumber_opts = "--format Cucumber::Formatter::ColorCommentFormatter"
21
+ end
22
+
23
+ task :default => :examples
24
+
25
+ require 'yard'
26
+ YARD::Rake::YardocTask.new do |t|
27
+ t.files = ['lib/**/*.rb', 'features/**/*.feature', 'features/**/*.rb', 'examples/**/*.rb']
28
+ t.options = ['-e./lib/yard-bench.rb', '--no-private']
29
+ end
30
+
31
+ task :list do
32
+ Rake.application.tasks.each do |task|
33
+ print task.name() + ' #' + task.comment.to_s() + "\n"
34
+ end
35
+ end
@@ -0,0 +1,6 @@
1
+ # config/cucumber.yml
2
+ ##YAML Template
3
+ ---
4
+ default: --profile yard
5
+ yard: --format Cucumber::Formatter::ColorCommentFormatter
6
+ standard: --format pretty
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../lib/dsl/bm_dsl'
4
+
5
+ # Example module to test benchmarking functionality.
6
+ module BmExamples
7
+ # Example class to test benchmarking functionality.
8
+ class BmExample
9
+ benchmark :do_it
10
+ ⌚ :do_other
11
+
12
+ # The value
13
+ attr_reader :value
14
+ # Constructor.
15
+ # @param value [Fixnum] the value to add to 10 within {#value} initializer.
16
+ # @param addval [Fixnum] another value to add to 10 within {#value} initializer.
17
+ # @param attrs [Hash] additional parameters (ignored.)
18
+ def initialize value, addval, *attrs
19
+ @value = 10 + value + addval
20
+ end
21
+ # Multiplies {#value} by parameter given.
22
+ # @param deg [Fixnum]
23
+ # @return [Fixnum] {#value} multiplied by deg.
24
+ def do_it deg
25
+ @value * deg
26
+ end
27
+ # Produces a power of the parameter given.
28
+ # @param base [Fixnum]
29
+ # @return [Fixnum] {#value} in a power of base
30
+ def do_other base = 2
31
+ @value ** base
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ Feature: The DSL for benchmarking within YARD documentation
2
+ In order to provide benchmarking within YARDoc
3
+ A developer uses DSL
4
+
5
+ # -----------------------------------------------------------
6
+ # -------------------- Callers --------------------------
7
+ # -----------------------------------------------------------
8
+
9
+ Scenario: ☎ is the method to create new instance of a class with suggested params if needed
10
+ Given I have a class with contructor requiring parameters
11
+ When I call a ☎ method on it
12
+ Then I have an instance of the class
13
+
14
+ Scenario: ☏ is the method to be called on an instance of the class with suggested params if needed
15
+ Given I have an instance method of the class requiring parameters
16
+ When I call a ☏ method for it
17
+ Then I have params suggested and the method called
18
+
19
+ # -----------------------------------------------------------
20
+ # -------------------- Measures -------------------------
21
+ # -----------------------------------------------------------
22
+
23
+ Scenario: The benchmarks set are to be processed with call to ::Kernel::⌛ method
24
+ Given I marked some methods as benchmarkable
25
+ When I call a ⌛ method
26
+ Then I yield all the benchmarks
27
+
28
+ Scenario: The benchmarks may be set with wildcards
29
+ Given I marked all methods of a class as benchmarkable via `:⋅`
30
+ When I call a ⌛ method
31
+ Then I yield all the benchmarks
32
+
33
+ Scenario: The only benchmark is to be returned properly for the class’ method
34
+ Given I marked all methods of a class as benchmarkable via `:⋅`
35
+ When I call a get method with `BmTests::BmTester`, `do_it` parameters
36
+ Then I yield the benchmarks for `do_it` method
@@ -0,0 +1,82 @@
1
+ Feature: Applying shorthands and some new methods to standard library
2
+ In order to make the coding a really delightful process
3
+ A developer uses new aliases/shorthands/functions and enjoys
4
+
5
+ # -----------------------------------------------------------
6
+ # -------------------- Kernel ---------------------------
7
+ # -----------------------------------------------------------
8
+
9
+ Scenario: λ is the alias for lambda
10
+ Given I define lambda with newly introduced λ alias
11
+ When I call a codeblock defined with “λ”
12
+ Then the code is being executed and returns proper value (squared param)
13
+
14
+ Scenario: λ is the proper lambda (parameter count aware) alias for lambda
15
+ Given I define lambda with newly introduced λ alias
16
+ When I call a codeblock defined with “λ” with wrong amount of arguments
17
+ Then I got ArgumentError as the result
18
+
19
+ Scenario: Λ is the alias for proc
20
+ Given I define proc with newly introduced Λ alias
21
+ When I call a codeblock defined with “Λ”
22
+ Then the code is being executed and returns proper value (squared param)
23
+
24
+ Scenario: Λ is the proc not lambda (parameter count unaware) alias for proc
25
+ Given I define proc with newly introduced Λ alias
26
+ When I call a codeblock defined with “Λ” with wrong amount of arguments
27
+ Then the code is being executed and returns proper value (squared param)
28
+
29
+ # -----------------------------------------------------------
30
+
31
+ Scenario: Random values for the supported classes should be produced
32
+ Given I define classset as default (String, Fixnum, Array, Hash)
33
+ When I ask for a random value on a classset
34
+ Then the random value should have one of the classes given
35
+
36
+ # -----------------------------------------------------------
37
+ # -------------------- Randoms --------------------------
38
+ # -----------------------------------------------------------
39
+
40
+ Scenario: Random value for the String class should be produced
41
+ Given I am `using YARD::MonkeyPatches`
42
+ When I call random of a size 1024 on a String instance
43
+ Then the random value should be generated of type String and have length of 1024
44
+
45
+ Scenario: Random value for the Fixnum class should be produced
46
+ Given I am `using YARD::MonkeyPatches`
47
+ When I call random on a Fixnum instance 1024
48
+ Then the random value should be generated of type Fixnum and be less than 1024
49
+
50
+ Scenario: Random value for the Array class should be produced
51
+ Given I am `using YARD::MonkeyPatches`
52
+ When I call random of a size 1024 on an Array instance
53
+ Then the random value should be generated of type Array and have length of 1024
54
+
55
+ Scenario: Random value for the Hash class should be produced
56
+ Given I am `using YARD::MonkeyPatches`
57
+ When I call random of a size 1024 on a Hash instance
58
+ Then the random value should be generated of type Hash and have length of 1024
59
+
60
+ # -----------------------------------------------------------
61
+ # -------------------- Singletons -----------------------
62
+ # -----------------------------------------------------------
63
+
64
+ Scenario: Random value for the String class should be produced by call to String.∀
65
+ Given I am `using YARD::MonkeyPatches`
66
+ When I call ∀ on a String class
67
+ Then the random value should be generated of type String and have default length of 32
68
+
69
+ Scenario: Random value for the Fixnum class should be produced by call to Fixnum.∀
70
+ Given I am `using YARD::MonkeyPatches`
71
+ When I call ∀ on a Fixnum class
72
+ Then the random value should be generated of type Fixnum and be not greater than 1024
73
+
74
+ Scenario: Random value for the Array class should be produced by call to Array.∀
75
+ Given I am `using YARD::MonkeyPatches`
76
+ When I call ∀ on an Array class with size parameter 64
77
+ Then the random value should be generated of type Array and have size of the parameter
78
+
79
+ Scenario: Random value for the Hash class should be produced by call to Hash.∀
80
+ Given I am `using YARD::MonkeyPatches`
81
+ When I call ∀ on a Hash class with size parameter 64
82
+ Then the random value should be generated of type Hash and have size of the parameter
@@ -0,0 +1,83 @@
1
+ # encoding: utf-8
2
+
3
+ require 'yard-bench'
4
+
5
+ using YARD::MonkeyPatches
6
+ using YARD::Bench
7
+
8
+ # @private
9
+ module BmTests
10
+ class BmTester
11
+ attr_reader :value
12
+ def initialize value, addval, *attrs
13
+ @value = 10 + value + addval
14
+ end
15
+ def do_it deg
16
+ @value * deg
17
+ end
18
+ def do_other base = 2
19
+ base * @value
20
+ end
21
+ end
22
+ end
23
+
24
+ # -----------------------------------------------------------
25
+ # -------------------- Callers --------------------------
26
+ # -----------------------------------------------------------
27
+
28
+ Given(/^I have a class with contructor requiring parameters$/) do
29
+ # BmTests::BmTester above
30
+ end
31
+
32
+ When(/^I call a ☎ method on it$/) do
33
+ @inst = BmTests::BmTester.☎
34
+ end
35
+
36
+ Then(/^I have an instance of the class$/) do
37
+ BmTests::BmTester === @inst
38
+ end
39
+
40
+ Given(/^I have an instance method of the class requiring parameters$/) do
41
+ # BmTests::BmTester.do_it above
42
+ end
43
+
44
+ When(/^I call a ☏ method for it$/) do
45
+ @res = BmTests::BmTester.☏ :do_it
46
+ end
47
+
48
+ Then(/^I have params suggested and the method called$/) do
49
+ puts @res
50
+ end
51
+
52
+ # -----------------------------------------------------------
53
+ # -------------------- Measures -------------------------
54
+ # -----------------------------------------------------------
55
+
56
+ Given(/^I marked some methods as benchmarkable$/) do
57
+ class String
58
+ benchmark :capitalize
59
+ end
60
+ end
61
+
62
+ Given(/^I marked all methods of a class as benchmarkable via `:⋅`$/) do
63
+ class BmTests::BmTester
64
+ benchmark :⋅
65
+ end
66
+ end
67
+
68
+ When(/^I call a ⌛ method$/) do
69
+ puts YARD::Bench::Marks.⌛
70
+ end
71
+
72
+ Then(/^I yield all the benchmarks$/) do
73
+ # pending # express the regexp above with the code you wish you had
74
+ end
75
+
76
+ When(/^I call a get method with `BmTests::BmTester`, `do_it` parameters$/) do
77
+ puts YARD::Bench::Marks.get 'BmTests::BmTester', 'do_it'
78
+ end
79
+
80
+ Then(/^I yield the benchmarks for `do_it` method$/) do
81
+ # pending # express the regexp above with the code you wish you had
82
+ end
83
+
@@ -0,0 +1,136 @@
1
+ # encoding: utf-8
2
+
3
+ require 'yard-bench'
4
+
5
+ using YARD::MonkeyPatches
6
+
7
+ # -----------------------------------------------------------
8
+ # -------------------- Kernel ---------------------------
9
+ # -----------------------------------------------------------
10
+
11
+ Given(/^I define lambda with newly introduced λ alias$/) do
12
+ @cb = λ { |a| a*2 }
13
+ @orig = lambda { |a| a*2 }
14
+ end
15
+
16
+ Given(/^I define proc with newly introduced Λ alias$/) do
17
+ @cb = Λ { |a| a*2 }
18
+ @orig = proc { |a| a*2 }
19
+ end
20
+
21
+ When(/^I call a codeblock defined with “(.*?)”$/) do |arg|
22
+ @result = @cb.call arg
23
+ @expected = @orig.call arg
24
+ end
25
+
26
+ Then(/^the code is being executed and returns proper value \(squared param\)$/) do
27
+ @expected == @result
28
+ end
29
+
30
+ When(/^I call a codeblock defined with “(.*?)” with wrong amount of arguments$/) do |arg|
31
+ @result = (@cb.call(arg, arg, arg) rescue $!)
32
+ end
33
+
34
+ Then(/^I got ArgumentError as the result$/) do
35
+ ArgumentError === @result
36
+ end
37
+
38
+ # -----------------------------------------------------------
39
+
40
+ Given(/^I define classset as default \((.*)\)$/) do |arg|
41
+ @c = instance_eval("[#{arg}]")
42
+ end
43
+
44
+ When(/^I ask for a random value on a classset$/) do
45
+ @r = random
46
+ end
47
+
48
+ Then(/^the random value should have one of the classes given$/) do
49
+ 10.times { @c.include? @r.class }
50
+ end
51
+
52
+ # -----------------------------------------------------------
53
+ # -------------------- Randoms --------------------------
54
+ # -----------------------------------------------------------
55
+
56
+ Given(/^I am `using YARD::MonkeyPatches`$/) do
57
+ # already using in the top of file
58
+ end
59
+
60
+ When(/^I call random of a size (\d+) on a String instance$/) do |sz|
61
+ @i = "".∀ :size => sz.to_i
62
+ end
63
+
64
+ Then(/^the random value should be generated of type String and have length of (\d*)$/) do |sz|
65
+ String === @i && sz.to_i == @i.length
66
+ puts "Generated String: “#{@i}”"
67
+ end
68
+
69
+ When(/^I call random on a Fixnum instance (\d+)$/) do |mx|
70
+ @i = mx.to_i.∀
71
+ end
72
+
73
+ Then(/^the random value should be generated of type Fixnum and be less than (\d+)$/) do |mx|
74
+ Fixnum === @i && @i < mx.to_i
75
+ puts "Generated Fixnum: “#{@i}”"
76
+ end
77
+
78
+ When(/^I call random of a size (\d+) on an Array instance$/) do |sz|
79
+ @i = [].∀ :size => sz.to_i
80
+ end
81
+
82
+ Then(/^the random value should be generated of type Array and have length of (\d+)$/) do |mx|
83
+ Array === @i && mx.to_i == @i.size
84
+ puts "Generated Array (1st element): “#{@i[0]}”"
85
+ end
86
+
87
+ When(/^I call random of a size (\d+) on a Hash instance$/) do |sz|
88
+ @i = {}.∀ :size => sz.to_i
89
+ end
90
+
91
+ Then(/^the random value should be generated of type Hash and have length of (\d+)$/) do |mx|
92
+ Hash === @i && mx.to_i == @i.size
93
+ puts "Generated Hash (1st element): “#{@i.first}”"
94
+ end
95
+
96
+ # -----------------------------------------------------------
97
+ # -------------------- Singletons -----------------------
98
+ # -----------------------------------------------------------
99
+
100
+ When(/^I call ∀ on a String class$/) do
101
+ @is = String.∀
102
+ end
103
+
104
+ Then(/^the random value should be generated of type String and have default length of (\d+)$/) do |sz|
105
+ String === @is && sz.to_i == @is.length
106
+ puts "Generated String: “#{@is}”"
107
+ end
108
+
109
+ When(/^I call ∀ on a Fixnum class$/) do
110
+ @if = Fixnum.∀
111
+ end
112
+
113
+ Then(/^the random value should be generated of type Fixnum and be not greater than (\d+)$/) do |maxval|
114
+ Fixnum === @if && @if < maxval.to_i
115
+ puts "Generated Fixnum: “#{@if}”"
116
+ end
117
+
118
+ When(/^I call ∀ on an Array class with size parameter (\d+)$/) do |sz|
119
+ @sz = sz.to_i
120
+ @ia = Array.∀ :size => @sz
121
+ end
122
+
123
+ Then(/^the random value should be generated of type Array and have size of the parameter$/) do
124
+ Array === @ia && @ia.size == @sz
125
+ puts "Generated Array (1st element): “#{@ia[0]}”"
126
+ end
127
+
128
+ When(/^I call ∀ on a Hash class with size parameter (\d+)$/) do |sz|
129
+ @sz = sz.to_i
130
+ @ih = Hash.∀ :size => @sz
131
+ end
132
+
133
+ Then(/^the random value should be generated of type Hash and have size of the parameter$/) do
134
+ Hash === @ih && @ih.size == @sz
135
+ puts "Generated Hash (1st element): “#{@ih.first}”"
136
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ # features/support/color-comment-formatter.rb
3
+
4
+ require 'rubygems'
5
+ require 'cucumber/formatter/pretty'
6
+
7
+ module Cucumber
8
+ module Formatter
9
+ class ColorCommentFormatter < Cucumber::Formatter::Pretty
10
+ def initialize(step_mother, io, options)
11
+ super(step_mother, io, options)
12
+ end
13
+
14
+ def comment_line comment_line
15
+ @io.puts(format_string(comment_line, :comment).indent(@indent))
16
+ @io.flush
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bundler/setup'
4
+ require 'yard-bench'
5
+ require 'rspec/expectations'