testdo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/features/support.rb +1 -0
- data/features/testdo.feature +39 -0
- data/lib/testdo/capture.rb +79 -0
- data/lib/testdo/version.rb +3 -0
- data/lib/testdo.rb +70 -0
- data/testdo.gemspec +22 -0
- metadata +90 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Alexander K
|
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,29 @@
|
|
1
|
+
# Testdo
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'testdo'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install testdo
|
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
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/features/support.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'aruba/cucumber'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
Feature: TestDO
|
2
|
+
|
3
|
+
Scenario:
|
4
|
+
Given a file named "file.rb" with:
|
5
|
+
"""
|
6
|
+
require 'testdo'
|
7
|
+
test do
|
8
|
+
1 == 1
|
9
|
+
2 == 2
|
10
|
+
/\d/ === '9'
|
11
|
+
end
|
12
|
+
"""
|
13
|
+
When I successfully run `ruby -S file.rb`
|
14
|
+
Then the output should contain exactly:
|
15
|
+
"""
|
16
|
+
OK: 3
|
17
|
+
|
18
|
+
"""
|
19
|
+
|
20
|
+
Scenario:
|
21
|
+
Given a file named "file.rb" with:
|
22
|
+
"""
|
23
|
+
require 'testdo'
|
24
|
+
test do
|
25
|
+
1 == 2
|
26
|
+
2 == 3
|
27
|
+
%w[a b].include? 'c'
|
28
|
+
end
|
29
|
+
"""
|
30
|
+
When I successfully run `ruby -S file.rb`
|
31
|
+
Then the output should contain exactly:
|
32
|
+
"""
|
33
|
+
Failed examples:
|
34
|
+
1 == 2
|
35
|
+
2 == 3
|
36
|
+
["a", "b"] include? "c"
|
37
|
+
OK: 0, failed: 3
|
38
|
+
|
39
|
+
"""
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Testdo
|
2
|
+
|
3
|
+
# used to outflank refinement
|
4
|
+
class Unwrap
|
5
|
+
def initialize obj; @obj = obj end
|
6
|
+
def send *a
|
7
|
+
obj.send *a
|
8
|
+
end
|
9
|
+
private; attr_reader :obj
|
10
|
+
def self.[] *a; new *a end
|
11
|
+
end
|
12
|
+
|
13
|
+
##############################################
|
14
|
+
# only for methods with one param right now! #
|
15
|
+
##############################################
|
16
|
+
# returns module with refinements that inform callback when specified messages sent to specified classes
|
17
|
+
def CaptureModule(classes_methods, &callback)
|
18
|
+
Module.new do
|
19
|
+
classes_methods.each do |classes,method_names|
|
20
|
+
[*classes].each do |klass|
|
21
|
+
refine klass do
|
22
|
+
[*method_names].each do |name|
|
23
|
+
define_method name do |other|
|
24
|
+
Unwrap[self].send(__method__,other).tap { |result| callback.call __method__,self,other,result }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# returns class that implement .eval(&block) and send all specified stuff to callback
|
34
|
+
def Capture classes_methods, &callback
|
35
|
+
Class.new do
|
36
|
+
extend Testdo
|
37
|
+
using CaptureModule(classes_methods, &callback)
|
38
|
+
|
39
|
+
def self.eval █
|
40
|
+
class_eval &block
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
if __FILE__== $0 # kind of usage
|
49
|
+
include Testdo
|
50
|
+
|
51
|
+
# CaptureModule
|
52
|
+
class Any
|
53
|
+
using CaptureModule(String => :+) { |m,a1,a2,result| @got = result } # don't try do-end block here
|
54
|
+
|
55
|
+
def self.eval &block
|
56
|
+
class_eval &block
|
57
|
+
self
|
58
|
+
end
|
59
|
+
class << self; attr_reader :got end
|
60
|
+
end
|
61
|
+
|
62
|
+
raise unless Any.eval { '1'+'1';nil }.got == '11'
|
63
|
+
raise unless Any.eval { '2'+'2';nil }.got == '22'
|
64
|
+
|
65
|
+
|
66
|
+
# Capture
|
67
|
+
got = nil
|
68
|
+
Capture([String,Fixnum] => [:+, :-]) { |m,a1,a2,result| got = result }.eval { '3'+'3';nil }
|
69
|
+
raise unless got == '33'
|
70
|
+
Capture([String,Fixnum] => [:+, :-]) { |m,a1,a2,result| got = result }.eval { 3+3;nil }
|
71
|
+
raise unless got == 6
|
72
|
+
|
73
|
+
|
74
|
+
# sort of no footprints
|
75
|
+
got = nil
|
76
|
+
Object.class_eval{ 'any'+'any'; 0 + 0 }
|
77
|
+
instance_eval{ 'any'+'any'; 0 + 0 }
|
78
|
+
raise unless got == nil
|
79
|
+
end
|
data/lib/testdo.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require "testdo/version"
|
2
|
+
require "testdo/capture"
|
3
|
+
|
4
|
+
|
5
|
+
def test &block
|
6
|
+
Testdo::Test.new.feed(&block).print
|
7
|
+
end
|
8
|
+
|
9
|
+
module Testdo
|
10
|
+
class Test
|
11
|
+
include Testdo
|
12
|
+
|
13
|
+
CAPTURE = {
|
14
|
+
[Fixnum, Range, String, NilClass, Regexp, TrueClass, FalseClass] => %i[== === > < =~],
|
15
|
+
[Array] => %i[include?] }
|
16
|
+
|
17
|
+
def initialize(capture: CAPTURE)
|
18
|
+
@capture = capture
|
19
|
+
@result = []
|
20
|
+
end
|
21
|
+
|
22
|
+
def feed &block
|
23
|
+
results = []
|
24
|
+
Capture(@capture) { |method,arg1,arg2,result|
|
25
|
+
text = "#{arg1.inspect} #{method.to_s} #{arg2.inspect}"
|
26
|
+
results << {text: text, result: result}
|
27
|
+
}.eval(&block)
|
28
|
+
|
29
|
+
@result.push *results
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
def print
|
34
|
+
successful = @result.select { |x| x[:result] }
|
35
|
+
failed = @result.select { |x| !x[:result] }
|
36
|
+
|
37
|
+
if failed.count > 0
|
38
|
+
puts 'Failed examples:'
|
39
|
+
failed.each { |result| puts result[:text] }
|
40
|
+
puts "OK: #{successful.count}, failed: #{failed.count}"
|
41
|
+
else
|
42
|
+
puts "OK: #{successful.count}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
__END__
|
49
|
+
# Class looks more flexible
|
50
|
+
|
51
|
+
def test watched=nil, &block
|
52
|
+
watched ||= {
|
53
|
+
[Fixnum, Range, String, NilClass, Regexp, TrueClass, FalseClass] => %i[== === > < =~],
|
54
|
+
[Array] => %i[include?] }
|
55
|
+
|
56
|
+
results = []
|
57
|
+
Watcher(watched) { |method,arg1,arg2,result|
|
58
|
+
text = "#{arg1.inspect} #{method.to_s} #{arg2.inspect}"
|
59
|
+
results << {text: text, result: result}
|
60
|
+
}.eval(&block)
|
61
|
+
|
62
|
+
successful = results.select { |x| x[:result] }
|
63
|
+
failed = results.select { |x| !x[:result] }
|
64
|
+
|
65
|
+
if failed.count > 0
|
66
|
+
puts 'Failed examples:'
|
67
|
+
failed.each do |result| puts result[:text] end
|
68
|
+
end
|
69
|
+
puts "OK: #{successful.count}, failed: #{failed.count}"
|
70
|
+
end
|
data/testdo.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'testdo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "testdo"
|
8
|
+
gem.version = Testdo::VERSION
|
9
|
+
gem.authors = ["Alexander K"]
|
10
|
+
gem.email = ["xpyro@ya.ru"]
|
11
|
+
gem.description = %q{extremely minimalistic unit test helper for ruby 2.0}
|
12
|
+
gem.summary = %q{extremely minimalistic unit test helper for ruby 2.0}
|
13
|
+
gem.homepage = "https://github.com/sowcow/testdo"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency('cucumber')
|
21
|
+
gem.add_development_dependency('aruba')
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: testdo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alexander K
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: cucumber
|
16
|
+
requirement: !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: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: aruba
|
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
|
+
description: extremely minimalistic unit test helper for ruby 2.0
|
47
|
+
email:
|
48
|
+
- xpyro@ya.ru
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- features/support.rb
|
59
|
+
- features/testdo.feature
|
60
|
+
- lib/testdo.rb
|
61
|
+
- lib/testdo/capture.rb
|
62
|
+
- lib/testdo/version.rb
|
63
|
+
- testdo.gemspec
|
64
|
+
homepage: https://github.com/sowcow/testdo
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.24
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: extremely minimalistic unit test helper for ruby 2.0
|
88
|
+
test_files:
|
89
|
+
- features/support.rb
|
90
|
+
- features/testdo.feature
|