testdo 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,13 +10,14 @@ Feature: TestDO
10
10
  /\d/ === '9'
11
11
  end
12
12
  """
13
- When I successfully run `ruby -S file.rb`
13
+ When I successfully run `ruby file.rb`
14
14
  Then the output should contain exactly:
15
15
  """
16
16
  OK: 3
17
17
 
18
18
  """
19
19
 
20
+
20
21
  Scenario:
21
22
  Given a file named "file.rb" with:
22
23
  """
@@ -27,7 +28,7 @@ Feature: TestDO
27
28
  %w[a b].include? 'c'
28
29
  end
29
30
  """
30
- When I successfully run `ruby -S file.rb`
31
+ When I successfully run `ruby file.rb`
31
32
  Then the output should contain exactly:
32
33
  """
33
34
  Failed examples:
@@ -36,4 +37,38 @@ Feature: TestDO
36
37
  ["a", "b"] include? "c"
37
38
  OK: 0, failed: 3
38
39
 
39
- """
40
+ """
41
+
42
+
43
+ Scenario:
44
+ Given a file named "file.rb" with:
45
+ """
46
+ require 'testdo'
47
+ test do
48
+ %w[a b].all? { |x|x.is_a? String }
49
+ end
50
+ """
51
+ When I successfully run `ruby file.rb`
52
+ Then the output should contain exactly:
53
+ """
54
+ OK: 1
55
+
56
+ """
57
+
58
+
59
+ Scenario:
60
+ Given a file named "file.rb" with:
61
+ """
62
+ require 'testdo'
63
+ test do
64
+ %w[a b].all? { false }
65
+ end
66
+ """
67
+ When I successfully run `ruby file.rb`
68
+ Then the output should contain exactly:
69
+ """
70
+ Failed examples:
71
+ ["a", "b"] all?
72
+ OK: 0, failed: 1
73
+
74
+ """
@@ -3,8 +3,8 @@ module Testdo
3
3
  # used to outflank refinement
4
4
  class Unwrap
5
5
  def initialize obj; @obj = obj end
6
- def send *a
7
- obj.send *a
6
+ def send *a,&b
7
+ obj.send *a,&b
8
8
  end
9
9
  private; attr_reader :obj
10
10
  def self.[] *a; new *a end
@@ -20,8 +20,8 @@ module Testdo
20
20
  [*classes].each do |klass|
21
21
  refine klass do
22
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 }
23
+ define_method name do |*arguments,&block|
24
+ Unwrap[self].send(__method__,*arguments,&block).tap { |result| callback.call self,__method__,arguments,block,result }
25
25
  end
26
26
  end
27
27
  end
@@ -50,7 +50,7 @@ if __FILE__== $0 # kind of usage
50
50
 
51
51
  # CaptureModule
52
52
  class Any
53
- using CaptureModule(String => :+) { |m,a1,a2,result| @got = result } # don't try do-end block here
53
+ using CaptureModule(String => :+, Array => :all?) { |receiver,msg,args,block,result| @got = result } # don't try do-end block here
54
54
 
55
55
  def self.eval &block
56
56
  class_eval &block
@@ -61,13 +61,14 @@ if __FILE__== $0 # kind of usage
61
61
 
62
62
  raise unless Any.eval { '1'+'1';nil }.got == '11'
63
63
  raise unless Any.eval { '2'+'2';nil }.got == '22'
64
-
64
+ raise unless Any.eval { [1,2].all?{true} }.got == true
65
+ raise unless Any.eval { [1,2].all?{false} }.got == false
65
66
 
66
67
  # Capture
67
68
  got = nil
68
- Capture([String,Fixnum] => [:+, :-]) { |m,a1,a2,result| got = result }.eval { '3'+'3';nil }
69
+ Capture([String,Fixnum] => [:+, :-]) { |receiver,msg,args,block,result| got = result }.eval { '3'+'3';nil }
69
70
  raise unless got == '33'
70
- Capture([String,Fixnum] => [:+, :-]) { |m,a1,a2,result| got = result }.eval { 3+3;nil }
71
+ Capture([String,Fixnum] => [:+, :-]) { |receiver,msg,args,block,result| got = result }.eval { 3+3;nil }
71
72
  raise unless got == 6
72
73
 
73
74
 
@@ -76,4 +77,6 @@ if __FILE__== $0 # kind of usage
76
77
  Object.class_eval{ 'any'+'any'; 0 + 0 }
77
78
  instance_eval{ 'any'+'any'; 0 + 0 }
78
79
  raise unless got == nil
80
+
81
+ puts 'OK'
79
82
  end
@@ -1,3 +1,3 @@
1
1
  module Testdo
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/testdo.rb CHANGED
@@ -12,7 +12,7 @@ module Testdo
12
12
 
13
13
  CAPTURE = {
14
14
  [Fixnum, Range, String, NilClass, Regexp, TrueClass, FalseClass] => %i[== === > < =~],
15
- [Array] => %i[include?] }
15
+ [Array] => %i[include? all? any? empty? one? none? member?] }
16
16
 
17
17
  def initialize(capture: CAPTURE)
18
18
  @capture = capture
@@ -20,13 +20,11 @@ module Testdo
20
20
  end
21
21
 
22
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}
23
+ Capture(@capture) { |receiver,msg,arguments,block,result|
24
+ text = "#{receiver.inspect} #{msg.to_s} #{arguments.map(&:inspect).join(', ')}"
25
+ @result << {text: text, result: result}
27
26
  }.eval(&block)
28
27
 
29
- @result.push *results
30
28
  self
31
29
  end
32
30
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testdo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-23 00:00:00.000000000 Z
12
+ date: 2013-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber