queencheck 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
1
  --default_path spec
2
2
  --color
3
- --format Fuubar
3
+ --format doc
data/.travis.yml CHANGED
@@ -1,3 +1,5 @@
1
+ bundler_args: --without development
2
+ script: bundle exec rake spec
1
3
  language: ruby
2
4
  rvm:
3
5
  - 1.8.7
data/Gemfile CHANGED
@@ -1,10 +1,13 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- group :development do
4
- gem "jeweler", ">= 1.8.3"
3
+ group :development, :test do
5
4
  gem "rake", ">= 0.9.2.2"
6
5
  gem "rspec", ">= 2.8.0"
7
6
  gem "fuubar", ">= 0.0.6"
7
+ end
8
+
9
+ group :development do
10
+ gem "jeweler", ">= 1.8.3"
8
11
  gem "growl", ">= 1.0.3"
9
12
  gem "spork", ">= 0.9.0.rc9"
10
13
  gem "rb-fsevent", ">= 0.9.0"
data/Rakefile CHANGED
@@ -3,8 +3,6 @@ require 'bundler'
3
3
  require 'rspec/core/rake_task'
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
7
-
8
6
  begin
9
7
  require 'jeweler'
10
8
  Jeweler::Tasks.new do |gemspec|
@@ -19,10 +17,14 @@ rescue LoadError
19
17
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
20
18
  end
21
19
 
22
- require 'yard'
23
- require 'yard/rake/yardoc_task'
24
- YARD::Rake::YardocTask.new do |t|
25
- t.files = ['lib/**/*.rb']
26
- t.options = ['--plugin=yard-tomdoc']
27
- t.options << '--debug' << '--verbose' if $trace
20
+ begin
21
+ require 'yard'
22
+ require 'yard/rake/yardoc_task'
23
+ YARD::Rake::YardocTask.new do |t|
24
+ t.files = ['lib/**/*.rb']
25
+ t.options = ['--plugin=yard-tomdoc']
26
+ t.options << '--debug' << '--verbose' if $trace
27
+ end
28
+ rescue LoadError
29
+ puts "YARD not available. Install it with: bundle install"
28
30
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.1.0
@@ -8,13 +8,13 @@ module QueenCheck
8
8
  class Core
9
9
  def initialize(instance, method, *types)
10
10
  @instance = instance
11
- @method = method.respond_to?(:call) ? method : instance.method(method.to_s.to_sym)
11
+ @method = method
12
12
  @types = types.map do | type |
13
13
  if type.respond_to?(:arbitrary?) && type.arbitrary?
14
14
  next type
15
15
  elsif type.kind_of?(Symbol)
16
- type = QueenCheck::Arbitrary::Instance.get_by_id(type)
17
- next type if type
16
+ arb = QueenCheck::Arbitrary::Instance.get_by_id(type)
17
+ next arb if arb
18
18
  end
19
19
  raise QueenCheck::Arbitrary::NotQueenCheckArbitrary, "`#{type}` is not implemented arbitrary"
20
20
  end
@@ -32,43 +32,9 @@ module QueenCheck
32
32
  arguments.push(type.arbitrary(range))
33
33
  end
34
34
 
35
- if config.verbose?
36
- arguments.each_with_index do | n, i |
37
- puts "#{@types[i]}: #{n}"
38
- end
39
- end
40
-
41
- result, error = nil, nil
42
- begin
43
- result = @method.call(*arguments)
44
- rescue Exception => e
45
- error = e
46
- end
47
-
48
- is_exception = false
49
- begin
50
- test_result = block.call(result, arguments, error)
51
- rescue Exception => e
52
- error = e
53
- is_exception = true
54
- end
55
-
56
- if config.verbose?
57
- print "#{@instance.kind_of?(Class) ? @instance.name : @instance.class.name} \##{@method.respond_to?(:name) ? @method.name : @method.class} ("
58
- print @types.map{|type| "#{type.name}" }.join(', ') + ')'
59
- puts " => #{is_exception ? error.class : test_result}"
60
- end
35
+ stats.push(QueenCheck::Core::Task.new(@instance, @method, arguments).run!(&block))
61
36
 
62
- unless is_exception
63
- case test_result
64
- when true
65
- stats.passes += 1
66
- when false
67
- stats.failures += 1
68
- end
69
- else
70
- stats.add_exception(error)
71
- end
37
+ puts taks.to_s(true) if config.verbose?
72
38
  end
73
39
 
74
40
  return stats
@@ -77,26 +43,68 @@ module QueenCheck
77
43
  class Result
78
44
  def initialize(examples)
79
45
  @examples = examples
80
- @passes = 0
81
- @failures = 0
82
- @exceptions = []
46
+ @tasks = []
47
+ end
48
+ attr_reader :examples
49
+
50
+ def push(obj)
51
+ @tasks.push(obj)
83
52
  end
84
- attr_reader :examples, :passes, :failures
85
53
 
86
- def passes=(n)
87
- raise RangeError if n > @examples
88
- @passes = n
54
+ def [](index)
55
+ @tasks[index]
89
56
  end
90
57
 
91
- def failures=(n)
92
- raise RangeError if n > @examples
93
- @failures = n
58
+ def passes
59
+ @tasks.reject {|task| !task.is_pass }.length
94
60
  end
95
61
 
96
- def exceptions; @exceptions.length; end
62
+ def failures
63
+ @tasks.reject {|task| task.is_pass }.length
64
+ end
97
65
 
98
- def add_exception(e)
99
- @exceptions.push(e)
66
+ def tasks(filter = :pass)
67
+ @tasks.reject {|task| task.is_pass == (filter == :pass ? false : true) }
68
+ end
69
+ end
70
+
71
+ class Task
72
+ def initialize(instance, method, args)
73
+ @is_pass = nil
74
+ @instance = instance
75
+ @method = method
76
+ @arguments = args
77
+ @result = nil
78
+ @exception = nil
79
+ end
80
+ attr_reader :is_pass, :instance, :method, :arguments, :result, :exception
81
+
82
+ def run!(&check_block)
83
+ return unless @is_pass.nil?
84
+ func = @method.respond_to?(:call) ? @method : @instance.method(@method)
85
+
86
+ begin
87
+ @result = func.call(*@arguments)
88
+ rescue Exception => e
89
+ @exception = e
90
+ end
91
+
92
+ @is_pass = !!check_block.call(@result, @arguments, @exception) if check_block
93
+
94
+ return self
95
+ end
96
+
97
+ def to_s(verbose = false)
98
+ if verbose
99
+ "<#{@instance.class.name}:#{@instance.object_id}>\##{@method.kind_of?(Method) ? @method.name : '::lambda::'}(" +
100
+ @arguments.map { |arg| "#{arg.class.name}:#{arg}" }.join(', ') +
101
+ ") => <#{@result.class.name}:#{@result}>" +
102
+ (!@is_pass ? " !! #{@exception.class.name}: #{@exception.message}" : '')
103
+ else
104
+ "#{@instance.class.name}\##{@method.respond_to?(:call) ? '::lambda::' : @method}(" +
105
+ @arguments.map {|arg| "#{arg}" } .join(', ') +
106
+ ") => #{@result}" + (!@is_pass ? "! #{@exception.class.name}: #{@exception.message}": '')
107
+ end
100
108
  end
101
109
  end
102
110
  end
@@ -0,0 +1,11 @@
1
+
2
+ begin
3
+ require 'queencheck'
4
+ rescue LoadError
5
+ require "pathname"
6
+ $:.unshift Pathname.new(File.expand_path('../../', __FILE__))
7
+ require 'queencheck'
8
+ end
9
+
10
+ require 'rspec'
11
+ require 'queencheck/rspec/dsl'
@@ -0,0 +1,18 @@
1
+ module RSpec
2
+ module Core
3
+ class ExampleGroup
4
+ def self.qcheck(instance, method, args, options = {}, &block)
5
+ QueenCheck(instance, method, *args).run(options) do | result, args, error |
6
+ it("#{instance}.#{method}(#{args.join(', ')})"){
7
+ begin
8
+ block.call(result, args, error)
9
+ rescue Exception => e
10
+ e.set_backtrace(e.backtrace.shift)
11
+ raise e
12
+ end
13
+ }
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -29,5 +29,14 @@ describe QueenCheck do
29
29
  ret.examples.should eq(100)
30
30
  ret.passes.should eq(100)
31
31
  end
32
- end
33
32
 
33
+ describe 'Task' do
34
+ it 'verbose' do
35
+ task = QueenCheck::Core::Task.new(1, :+, [1])
36
+
37
+ task.run! do | result, arguments, error |
38
+ result != arguments[0]
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,19 @@
1
+ require 'queencheck/rspec'
2
+
3
+ describe 'QueenCheck::RSpec' do
4
+ qcheck 1, :+, [Integer] do | result, arguments, exception |
5
+ result.should == arguments[0] + 1
6
+ end
7
+
8
+ qcheck 1, :/, [Integer] do | result, arguments, exception |
9
+ if exception
10
+ if exception.kind_of?(ZeroDivisionError)
11
+ arguments[0].should == 0
12
+ else
13
+ raise exception
14
+ end
15
+ else
16
+ result.should == 1 / arguments[0]
17
+ end
18
+ end
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: queencheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,52 +12,52 @@ cert_chain: []
12
12
  date: 2012-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: jeweler
16
- requirement: &70352749528960 !ruby/object:Gem::Requirement
15
+ name: rake
16
+ requirement: &70175906897620 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.8.3
21
+ version: 0.9.2.2
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70352749528960
24
+ version_requirements: *70175906897620
25
25
  - !ruby/object:Gem::Dependency
26
- name: rake
27
- requirement: &70352749562760 !ruby/object:Gem::Requirement
26
+ name: rspec
27
+ requirement: &70175906897140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: 0.9.2.2
32
+ version: 2.8.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70352749562760
35
+ version_requirements: *70175906897140
36
36
  - !ruby/object:Gem::Dependency
37
- name: rspec
38
- requirement: &70352749562220 !ruby/object:Gem::Requirement
37
+ name: fuubar
38
+ requirement: &70175906896660 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
42
42
  - !ruby/object:Gem::Version
43
- version: 2.8.0
43
+ version: 0.0.6
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70352749562220
46
+ version_requirements: *70175906896660
47
47
  - !ruby/object:Gem::Dependency
48
- name: fuubar
49
- requirement: &70352749561680 !ruby/object:Gem::Requirement
48
+ name: jeweler
49
+ requirement: &70175906896160 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.0.6
54
+ version: 1.8.3
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70352749561680
57
+ version_requirements: *70175906896160
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: growl
60
- requirement: &70352749561200 !ruby/object:Gem::Requirement
60
+ requirement: &70175906895660 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.0.3
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70352749561200
68
+ version_requirements: *70175906895660
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: spork
71
- requirement: &70352749560720 !ruby/object:Gem::Requirement
71
+ requirement: &70175906895160 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.9.0.rc9
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70352749560720
79
+ version_requirements: *70175906895160
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rb-fsevent
82
- requirement: &70352749560240 !ruby/object:Gem::Requirement
82
+ requirement: &70175906894680 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 0.9.0
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70352749560240
90
+ version_requirements: *70175906894680
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: guard-spork
93
- requirement: &70352749559740 !ruby/object:Gem::Requirement
93
+ requirement: &70175906894180 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 0.5.1
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70352749559740
101
+ version_requirements: *70175906894180
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: guard-rspec
104
- requirement: &70352749559220 !ruby/object:Gem::Requirement
104
+ requirement: &70175906893680 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 0.6.0
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70352749559220
112
+ version_requirements: *70175906893680
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: guard-bundler
115
- requirement: &70352749558740 !ruby/object:Gem::Requirement
115
+ requirement: &70175906893200 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 0.1.3
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70352749558740
123
+ version_requirements: *70175906893200
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: guard-yard
126
- requirement: &70352749558260 !ruby/object:Gem::Requirement
126
+ requirement: &70175906892720 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: 1.0.2
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *70352749558260
134
+ version_requirements: *70175906892720
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: yard
137
- requirement: &70352749557760 !ruby/object:Gem::Requirement
137
+ requirement: &70175906892220 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: 0.7.4
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *70352749557760
145
+ version_requirements: *70175906892220
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: yard-tomdoc
148
- requirement: &70352749557260 !ruby/object:Gem::Requirement
148
+ requirement: &70175895215600 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,7 +153,7 @@ dependencies:
153
153
  version: 0.3.0
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *70352749557260
156
+ version_requirements: *70175895215600
157
157
  description: QueenCheck is random test library. Inspired by QuickCheck library in
158
158
  Haskell.
159
159
  email: rosylilly@aduca.org
@@ -179,12 +179,15 @@ files:
179
179
  - lib/queencheck/elements_of.rb
180
180
  - lib/queencheck/float.rb
181
181
  - lib/queencheck/integer.rb
182
+ - lib/queencheck/rspec.rb
183
+ - lib/queencheck/rspec/dsl.rb
182
184
  - lib/queencheck/string.rb
183
185
  - queencheck.gemspec
184
186
  - spec/queencheck/arbitrary_spec.rb
185
187
  - spec/queencheck/core_spec.rb
186
188
  - spec/queencheck/elements_of_spec.rb
187
189
  - spec/queencheck/integer_spec.rb
190
+ - spec/queencheck/rspec_spec.rb
188
191
  - spec/queencheck/string_spec.rb
189
192
  - spec/spec_helper.rb
190
193
  homepage: https://github.com/rosylilly/QueenCheck