rspec-fixture 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,63 +1,189 @@
1
- ----------------------------------------------------------------------
2
- r3507 (orig r6556): walf443 | 2008-02-11 17:34:20 +0900
3
-
4
- lang/ruby/rspec-fixture: added DESCRIPTION for Rakefile
5
- ----------------------------------------------------------------------
6
- r3505 (orig r6554): walf443 | 2008-02-11 17:23:32 +0900
7
-
8
- lang/ruby/rspec-fixture: wrote README
9
- ----------------------------------------------------------------------
10
- r3502 (orig r6551): walf443 | 2008-02-11 16:34:52 +0900
11
-
12
- lang/ruby/rspec-fixture: fix example's output message
13
- ----------------------------------------------------------------------
14
- r3490 (orig r6539): walf443 | 2008-02-11 13:04:48 +0900
15
-
16
- lang/ruby/rspec-fixture:
17
- - fix a bug that is 'not converting collectly :msg in description template'.
18
- - add spec-fixture-base spec.
19
- ----------------------------------------------------------------------
20
- r3475 (orig r6524): walf443 | 2008-02-11 01:08:54 +0900
21
-
22
- lang/ruby/rspec-fixture: generated class with filter should behave like 'generated_class'
23
- ----------------------------------------------------------------------
24
- r3474 (orig r6523): walf443 | 2008-02-11 01:07:59 +0900
25
-
26
- lang/ruby/rspec-fixture: load library not in each spec file, but spec_helper.rb.
27
- ----------------------------------------------------------------------
28
- r3473 (orig r6522): walf443 | 2008-02-11 00:59:39 +0900
29
-
30
- lang/ruby/rspec-fixture: delete extra file and change to load library in shared helper.
31
- ----------------------------------------------------------------------
32
- r3472 (orig r6521): walf443 | 2008-02-11 00:57:32 +0900
33
-
34
- lang/ruby/rspec-fixture: add _define_fixture spec and fix some bug.
35
- ----------------------------------------------------------------------
36
- r3471 (orig r6520): walf443 | 2008-02-11 00:30:29 +0900
37
-
38
- lang/ruby/rspc-fixture: fix spec task for executing coverage test collectly.
39
- ----------------------------------------------------------------------
40
- r3453 (orig r6502): walf443 | 2008-02-10 18:52:37 +0900
41
-
42
- lang/ruby/rspec-fixture: add spec for with_fixture method
43
- ----------------------------------------------------------------------
44
- r3415 (orig r6464): walf443 | 2008-02-10 05:02:25 +0900
45
-
46
- lang/ruby/rspec-fixture:
47
- - support desc_filters for customizing description flexibly.
48
- - change desc_template value to use raw input value's inspect
49
- ----------------------------------------------------------------------
50
- r3408 (orig r6457): walf443 | 2008-02-10 01:39:04 +0900
51
-
52
- lang/ruby/rspec-fixture:
53
- - raise NameError when with_fixtures arg duplicate to reserved name.
54
- - just use msg when description template was not exist.
55
- ----------------------------------------------------------------------
56
- r3404 (orig r6453): walf443 | 2008-02-10 00:06:50 +0900
57
-
58
- lang/ruby/rspec-fixture: support filters, spec template for description
59
- ----------------------------------------------------------------------
60
- r3314 (orig r6363): walf443 | 2008-02-08 09:42:35 +0900
61
-
62
- lang/ruby/rspec-fixture: import new project.
63
- ----------------------------------------------------------------------
1
+ commit 8740a1ef1b245f9aee00255ec1eb105d4685e79f
2
+ Author: Keiji, Yoshimi <walf443@gmail.com>
3
+ Date: Fri Nov 14 00:41:51 2008 +0900
4
+
5
+ support mutiple examples in with_fixtures context.
6
+
7
+ commit 978d41174796bf6ee7dcd0e97a2d2d448636ec76
8
+ Author: Keiji, Yoshimi <walf443@gmail.com>
9
+ Date: Sat Nov 8 16:14:36 2008 +0900
10
+
11
+ fixed uninintialized instance variable warnings.
12
+
13
+ commit 8348e1bcbfc2d026d1a470237d9d220644825caa
14
+ Author: Keiji, Yoshimi <walf443@gmail.com>
15
+ Date: Tue Sep 16 07:35:51 2008 +0900
16
+
17
+ change for not raising Error in Rakefile without library.
18
+
19
+ commit 1fd4343bbb61650cea3b298ad5c4878e019bcffe
20
+ Author: Keiji, Yoshimi <walf443 at gmail dot com>
21
+ Date: Sat May 3 16:24:22 2008 +0900
22
+
23
+ it may be better to return nil
24
+
25
+ commit 8767a87d37c113ec6e56b117b927da40218b1da8
26
+ Author: Keiji, Yoshimi <walf443 at gmail dot com>
27
+ Date: Sat May 3 16:08:33 2008 +0900
28
+
29
+ change variable name.
30
+
31
+ commit e8848263e3a766d3cc1cd931ba8fff39a7c17666
32
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
33
+ Date: Sat Feb 16 13:18:39 2008 +0000
34
+
35
+ lang/ruby/rspec-fixture: added named filter feature.
36
+
37
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6782 d0d07461-0603-4401-acd4-de1884942a52
38
+
39
+ commit 5e2532abc128d35c36ad2f73fa817ef70bffa544
40
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
41
+ Date: Wed Feb 13 23:50:34 2008 +0000
42
+
43
+ lang/ruby/rspec-fixture: changed to shuffle fixtures for not writing a test with order dependency.
44
+
45
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6657 d0d07461-0603-4401-acd4-de1884942a52
46
+
47
+ commit 5953fa205a8da67fd389b5ab9dbb606e39132e1a
48
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
49
+ Date: Tue Feb 12 15:30:01 2008 +0000
50
+
51
+ lang/ruby/rspec-fixture: changed _example method to behave same as _input method.
52
+
53
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6614 d0d07461-0603-4401-acd4-de1884942a52
54
+
55
+ commit 00836de4fafc20e520937b9c66b717cfe27d4744
56
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
57
+ Date: Mon Feb 11 09:24:27 2008 +0000
58
+
59
+ lang/ruby/rspec-fixture: added rubyforge project id of this project.
60
+
61
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6560 d0d07461-0603-4401-acd4-de1884942a52
62
+
63
+ commit 543a585aedb5009348a882e99777c0b15d89b225
64
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
65
+ Date: Mon Feb 11 09:09:12 2008 +0000
66
+
67
+ lang/ruby/rspec-fixture:
68
+ - updated ChangeLog from svk log
69
+ - added document for Spec::Fixture::Base's each methods.
70
+
71
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6558 d0d07461-0603-4401-acd4-de1884942a52
72
+
73
+ commit 8f379c8361e34118e5e3704175afd4072ef4999d
74
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
75
+ Date: Mon Feb 11 08:34:20 2008 +0000
76
+
77
+ lang/ruby/rspec-fixture: added DESCRIPTION for Rakefile
78
+
79
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6556 d0d07461-0603-4401-acd4-de1884942a52
80
+
81
+ commit e694dd45f0eacf763591cb073a2cdc0ccc47a583
82
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
83
+ Date: Mon Feb 11 08:23:32 2008 +0000
84
+
85
+ lang/ruby/rspec-fixture: wrote README
86
+
87
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6554 d0d07461-0603-4401-acd4-de1884942a52
88
+
89
+ commit 9f5bdbf58798241af016e515703958ca2ef3846b
90
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
91
+ Date: Mon Feb 11 07:34:52 2008 +0000
92
+
93
+ lang/ruby/rspec-fixture: fix example's output message
94
+
95
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6551 d0d07461-0603-4401-acd4-de1884942a52
96
+
97
+ commit f403cb774c0dc96ac76e4e2edf8f7da552f5a076
98
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
99
+ Date: Mon Feb 11 04:04:48 2008 +0000
100
+
101
+ lang/ruby/rspec-fixture:
102
+ - fix a bug that is 'not converting collectly :msg in description template'.
103
+ - add spec-fixture-base spec.
104
+
105
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6539 d0d07461-0603-4401-acd4-de1884942a52
106
+
107
+ commit 7035e40723789275086d305d1f484ff1eb27b013
108
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
109
+ Date: Sun Feb 10 16:08:54 2008 +0000
110
+
111
+ lang/ruby/rspec-fixture: generated class with filter should behave like 'generated_class'
112
+
113
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6524 d0d07461-0603-4401-acd4-de1884942a52
114
+
115
+ commit 5ee9583f75ff3aeb51146081ee50afc177248d15
116
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
117
+ Date: Sun Feb 10 16:07:59 2008 +0000
118
+
119
+ lang/ruby/rspec-fixture: load library not in each spec file, but spec_helper.rb.
120
+
121
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6523 d0d07461-0603-4401-acd4-de1884942a52
122
+
123
+ commit 33712131a5425d9eca0416b72ba0300588db76ad
124
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
125
+ Date: Sun Feb 10 15:59:39 2008 +0000
126
+
127
+ lang/ruby/rspec-fixture: delete extra file and change to load library in shared helper.
128
+
129
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6522 d0d07461-0603-4401-acd4-de1884942a52
130
+
131
+ commit ffbc76bf35c2960ff27e951b648b61685f7260b2
132
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
133
+ Date: Sun Feb 10 15:57:32 2008 +0000
134
+
135
+ lang/ruby/rspec-fixture: add _define_fixture spec and fix some bug.
136
+
137
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6521 d0d07461-0603-4401-acd4-de1884942a52
138
+
139
+ commit b043faecc73bfafae9eab4eccf6dfe5f9bda2922
140
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
141
+ Date: Sun Feb 10 15:30:29 2008 +0000
142
+
143
+ lang/ruby/rspc-fixture: fix spec task for executing coverage test collectly.
144
+
145
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6520 d0d07461-0603-4401-acd4-de1884942a52
146
+
147
+ commit 1c84a9cba1255dc566e6a231cc8ef76f78b4592f
148
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
149
+ Date: Sun Feb 10 09:52:37 2008 +0000
150
+
151
+ lang/ruby/rspec-fixture: add spec for with_fixture method
152
+
153
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6502 d0d07461-0603-4401-acd4-de1884942a52
154
+
155
+ commit e37779df95db12d2fef080e3cc890db84a408ab4
156
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
157
+ Date: Sat Feb 9 20:02:25 2008 +0000
158
+
159
+ lang/ruby/rspec-fixture:
160
+ - support desc_filters for customizing description flexibly.
161
+ - change desc_template value to use raw input value's inspect
162
+
163
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6464 d0d07461-0603-4401-acd4-de1884942a52
164
+
165
+ commit f31cc321b6329b2f6e9121110d91932410ed87e3
166
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
167
+ Date: Sat Feb 9 16:39:04 2008 +0000
168
+
169
+ lang/ruby/rspec-fixture:
170
+ - raise NameError when with_fixtures arg duplicate to reserved name.
171
+ - just use msg when description template was not exist.
172
+
173
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6457 d0d07461-0603-4401-acd4-de1884942a52
174
+
175
+ commit 6439b8c043f58102aa1ce878d89416625aa9cefe
176
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
177
+ Date: Sat Feb 9 15:06:50 2008 +0000
178
+
179
+ lang/ruby/rspec-fixture: support filters, spec template for description
180
+
181
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6453 d0d07461-0603-4401-acd4-de1884942a52
182
+
183
+ commit d9a069ff5d8ab781d587fce2ec1a4e88fe8ebe8e
184
+ Author: walf443 <walf443@d0d07461-0603-4401-acd4-de1884942a52>
185
+ Date: Fri Feb 8 00:42:35 2008 +0000
186
+
187
+ lang/ruby/rspec-fixture: import new project.
188
+
189
+ git-svn-id: http://svn.coderepos.org/share/lang/ruby/rspec-fixture/trunk@6363 d0d07461-0603-4401-acd4-de1884942a52
data/Rakefile CHANGED
@@ -17,8 +17,8 @@ DESCRIPTION = <<-"END_DESCRIPTION"
17
17
  Test::Base like DSL for RSpec
18
18
  END_DESCRIPTION
19
19
  BIN_FILES = %w( )
20
- VERS = "0.0.1"
21
- RUBYFORGE_PACKAGE_ID = 7007
20
+ VERS = "0.0.2"
21
+ RUBYFORGE_PROJECT_ID = 7007
22
22
 
23
23
  EXTRA_RDOC_FILES = []
24
24
  HECKLE_ROOT_MODULES = ["Spec::Fixture"]
@@ -7,5 +7,6 @@ module Spec
7
7
  end
8
8
  end
9
9
 
10
+ require 'spec/fixture/filter'
10
11
  require 'spec/fixture/base'
11
12
  require 'spec/fixture/extentions/example/example_group_methods'
@@ -3,11 +3,14 @@ class Spec::Fixture::Base
3
3
 
4
4
  def initialize binding, hash, &block
5
5
  @binding = binding
6
- input_names, expected_name = *hash.to_a.first
6
+ input_names, expected_names = *hash.to_a.first
7
7
  unless input_names.kind_of? Array
8
8
  input_names = [ input_names ]
9
9
  end
10
- _define_fixture(input_names, expected_name)
10
+ unless expected_names.kind_of? Array
11
+ expected_names = [ expected_names ]
12
+ end
13
+ _define_fixture(input_names, expected_names)
11
14
  instance_eval(&block)
12
15
  end
13
16
 
@@ -19,13 +22,13 @@ class Spec::Fixture::Base
19
22
  # please use +desc_filters+.
20
23
  #
21
24
  # Block should take argumentes in order input, expected.
22
- # input was a Hash in input has two or larger members.
23
- # When input has only a member, input has filtered value.
25
+ # input and expected was a Hash in input has two or larger members.
26
+ # When input and expected has only a member, input has filtered value.
24
27
  def it desc=nil, &example
25
- if desc
26
- @desc_template = desc
27
- end
28
- @example_shared_runner = example
28
+ @desc_template ||= []
29
+ @desc_template << desc
30
+ @example_shared_runner ||= []
31
+ @example_shared_runner << example
29
32
  end
30
33
 
31
34
  # You specify test data in this methods.
@@ -35,16 +38,19 @@ class Spec::Fixture::Base
35
38
  @fixtures = data.map do |item|
36
39
  fxt, msg = *item
37
40
  input, expected = *fxt.to_a.first
38
- @class.new input, expected, msg, @filter_of
39
- end
41
+ filter_of = instance_variable_defined?('@filter_of') ? @filter_of : nil
42
+ @class.new input, expected, msg, filter_of
43
+ end.sort_by { rand } # you should write test to pass without order dependency.
40
44
  end
41
45
 
42
46
  # If you specify +filters+, you can use filtered value in +it+'s block
43
47
  # filters argument is hash that has a key of members.
44
48
  # value should be string or symbol or Array that contain strings or symbols or Proc.
45
49
  # In case value is Proc, filtered value is Proc's result.
46
- # In case value is Array, each item was applyed using Object#__send__.
47
- # In case value is string or symbol, same the above.
50
+ # In case value is Array, each item applyed by following rule.
51
+ # In case item is String that start from ".", for example ".uri", filter use Spec::Fixture::Filter module_functions
52
+ # Otherwise, Object#__send__ was applyed.
53
+ # If it has only a filter, you can omit bracket and applyed following above.
48
54
  def filters hash
49
55
  @filter_of = hash
50
56
  end
@@ -55,20 +61,26 @@ class Spec::Fixture::Base
55
61
  @desc_filter_of = hash
56
62
  end
57
63
 
58
- def generate_msg fxt #:nodoc:
59
- if @desc_template
60
- msg = @desc_template
64
+ def generate_msg fxt, desc_template #:nodoc:
65
+ if desc_template
66
+ msg = desc_template
61
67
  [ fxt._members, :msg ].flatten.each do |item|
62
68
  if item == :msg
63
69
  result = fxt.msg.to_s
64
70
  else
65
71
  result = fxt.value_of[item]
66
- if @desc_filter_of && @desc_filter_of[item]
72
+ if instance_variable_defined?('@desc_filter_of') && @desc_filter_of && @desc_filter_of[item]
67
73
  if @desc_filter_of[item].kind_of? Proc
68
74
  result = @desc_filter_of[item].call(result)
69
75
  else
70
- [ @desc_filter_of[item] ].flatten.each do |meth|
71
- result = result.__send__ meth
76
+ [ @desc_filter_of[item] ].flatten.each do |filter|
77
+ # XXX: Proc filter can not use in Array.
78
+ # It's simple, it think, do all in a proc.
79
+ if filter.to_s =~ /^\./
80
+ result = Spec::Fixture::Filter.__send__(filter.to_s.sub(/^\./, ''), result)
81
+ else
82
+ result = result.__send__ filter
83
+ end
72
84
  end
73
85
  end
74
86
  else
@@ -83,18 +95,22 @@ class Spec::Fixture::Base
83
95
  if fxt.msg
84
96
  fxt.msg
85
97
  else
86
- ""
98
+ nil
87
99
  end
88
100
  end
89
101
  end
90
102
 
91
103
  def run #:nodoc:
92
104
  fixture = self
105
+ desc_template = @desc_template
93
106
  @binding.module_eval do
94
107
  if fixture.fixtures
95
108
  fixture.fixtures.each do |fxt|
96
- it fixture.generate_msg(fxt) do
97
- fixture.example_shared_runner.call(fxt._input, fxt._expected)
109
+ fixture.example_shared_runner.sort_by { rand }.each_with_index do |runner,index|
110
+ msg = fixture.generate_msg(fxt, desc_template.nil? ? nil : desc_template[index] )
111
+ it msg do
112
+ runner.call(fxt._input, fxt._expected)
113
+ end
98
114
  end
99
115
  end
100
116
  end
@@ -102,7 +118,7 @@ class Spec::Fixture::Base
102
118
  end
103
119
 
104
120
  # generate temp class for fixture.
105
- def _define_fixture input, expected #:nodoc:
121
+ def _define_fixture __input, __expected #:nodoc:
106
122
  klass = Class.new
107
123
  klass.class_eval do
108
124
  attr_reader :filter_of, :value_of, :msg
@@ -110,40 +126,39 @@ class Spec::Fixture::Base
110
126
  define_method :initialize do |_input, _expected, msg, filter_of|
111
127
  @value_of = {}
112
128
  @filter_of = filter_of ? filter_of : {}
113
- if input.size == 1
114
- key = input.first
115
- @value_of[key] = _input
116
- else
117
- input.zip(_input) do |key, value|
118
- @value_of[key] = value
129
+ [ [__input, _input], [__expected, _expected] ].each do |input_or_expected|
130
+ if input_or_expected.first.size == 1
131
+ key = input_or_expected.first.first
132
+ @value_of[key] = input_or_expected.last
133
+ else
134
+ input_or_expected.first.zip(input_or_expected.last) do |key, value|
135
+ @value_of[key] = value
136
+ end
119
137
  end
120
138
  end
121
- @value_of[expected] = _expected
122
139
  @msg = msg
123
140
  end
124
141
 
125
142
  define_method :_members do
126
- [ input, expected].flatten
143
+ [ __input, __expected].flatten
127
144
  end
128
145
 
129
- define_method :_expected do
130
- __send__ expected
131
- end
146
+ [ [__input, :_input], [__expected, :_expected] ].each do |input_or_expected|
147
+ define_method input_or_expected.last do
148
+ if input_or_expected.first.size == 1
149
+ __send__(input_or_expected.first.first)
150
+ else
151
+ result_of = {}
152
+ input_or_expected.first.each do |item|
153
+ result_of[item] = __send__ item
154
+ end
132
155
 
133
- define_method :_input do
134
- if input.size == 1
135
- __send__(input.first)
136
- else
137
- result_of = {}
138
- input.each do |item|
139
- result_of[item] = __send__ item
156
+ result_of
140
157
  end
141
-
142
- result_of
143
158
  end
144
159
  end
145
160
 
146
- [ input, expected ].flatten.each do |item|
161
+ [ __input, __expected ].flatten.each do |item|
147
162
  raise NameError if instance_methods.map{|i| i.to_s }.include? item.to_s
148
163
 
149
164
  define_method item do
@@ -153,7 +168,13 @@ class Spec::Fixture::Base
153
168
  else
154
169
  if @filter_of[item]
155
170
  [ @filter_of[item] ].flatten.each do |filter|
156
- result = result.__send__ filter
171
+ # XXX: Proc filter can not use in Array.
172
+ # It's simple, it think, do all in a proc.
173
+ if filter.to_s =~ /^\./
174
+ result = Spec::Fixture::Filter.__send__(filter.to_s.sub(/^\./, ''), result)
175
+ else
176
+ result = result.__send__ filter
177
+ end
157
178
  end
158
179
  end
159
180
  end
@@ -0,0 +1,56 @@
1
+ module Spec::Fixture::Filter
2
+ constants.each do |const|
3
+ extend const
4
+ end
5
+
6
+ class << self
7
+ def eval str
8
+ eval(str.to_s)
9
+ end
10
+
11
+ def timep str
12
+ require 'time'
13
+ Time.parse(str.to_s)
14
+ end
15
+
16
+ def html_escape str
17
+ require 'cgi'
18
+ CGI.escapeHTML(str.to_s)
19
+ end
20
+
21
+ def html_unescape str
22
+ require 'cgi'
23
+ CGI.unescapeHTML(str.to_s)
24
+ end
25
+
26
+ def pathname str
27
+ require 'pathname'
28
+ Pathname.new(str.to_s)
29
+ end
30
+
31
+ def uri str
32
+ require 'uri'
33
+ URI.new(str.to_s)
34
+ end
35
+
36
+ def uri_encode str
37
+ require 'uri'
38
+ URI.encode(str.to_s)
39
+ end
40
+
41
+ def uri_decode str
42
+ require 'uri'
43
+ URI.decode(str.to_s)
44
+ end
45
+
46
+ def base64_encode str
47
+ require 'base64'
48
+ Base64.encode64(str.to_s)
49
+ end
50
+
51
+ def base64_decode str
52
+ require 'base64'
53
+ Base64.decode64(str.to_s)
54
+ end
55
+ end
56
+ end
@@ -23,27 +23,27 @@ describe Spec::Fixture::Base do
23
23
  end
24
24
 
25
25
  it 'should generate some class' do
26
- @fixuture_base._define_fixture(:foo, :bar).should be_kind_of(Class)
26
+ @fixuture_base._define_fixture([:foo], [:bar]).should be_kind_of(Class)
27
27
  end
28
28
 
29
29
  %w(_input _expected _members filter_of value_of msg).each do |reserved_name|
30
30
  it "should raise NameError when using #{reserved_name} for arguments" do
31
31
  lambda {
32
- @fixuture_base._define_fixture(reserved_name, :foo)
32
+ @fixuture_base._define_fixture([reserved_name], [:foo])
33
33
  }.should raise_error(NameError)
34
34
  end
35
35
  end
36
36
 
37
37
  it 'should raise NameError when specify same name for arguments' do
38
38
  lambda {
39
- @fixuture_base._define_fixture([:foo], :foo)
39
+ @fixuture_base._define_fixture([:foo], [:foo])
40
40
  }.should raise_error(NameError)
41
41
  end
42
42
 
43
43
  describe 'generated class', 'when one input, one expected' do
44
44
  before do
45
- @class = @fixuture_base._define_fixture([:foo], :bar)
46
- @class_instance = @class.new([:foo], :bar, nil, nil)
45
+ @class = @fixuture_base._define_fixture([:foo], [:bar])
46
+ @class_instance = @class.new([:foo], [:bar], nil, nil)
47
47
  end
48
48
 
49
49
  it_should_behave_like 'generated_class'
@@ -63,8 +63,8 @@ describe Spec::Fixture::Base do
63
63
 
64
64
  describe 'generated class', 'when two input, one expected' do
65
65
  before do
66
- @class = @fixuture_base._define_fixture([:foo, :bar], :baz)
67
- @class_instance = @class.new([:foo, :bar], :baz, nil, nil)
66
+ @class = @fixuture_base._define_fixture([:foo, :bar], [:baz])
67
+ @class_instance = @class.new([:foo, :bar], [:baz], nil, nil)
68
68
  end
69
69
 
70
70
  it_should_behave_like 'generated_class'
@@ -84,15 +84,42 @@ describe Spec::Fixture::Base do
84
84
  }
85
85
  end
86
86
  end
87
+
88
+ describe 'generated class', 'when two input, two expected' do
89
+ before do
90
+ @class = @fixuture_base._define_fixture([:foo, :bar], [:baz, :zoo])
91
+ @class_instance = @class.new([:foo, :bar], [:baz, :zoo], nil, nil)
92
+ end
93
+
94
+ it_should_behave_like 'generated_class'
95
+
96
+ it 'should have members list' do
97
+ @class_instance._members.should == [:foo, :bar, :baz, :zoo]
98
+ end
99
+
100
+ it '_expected method should return expected members method result Hash' do
101
+ @class_instance._expected.should == {
102
+ :baz => @class_instance.baz,
103
+ :zoo => @class_instance.zoo
104
+ }
105
+ end
106
+
107
+ it '_input method should return input members method result Hash' do
108
+ @class_instance._input.should == {
109
+ :foo => @class_instance.foo,
110
+ :bar => @class_instance.bar
111
+ }
112
+ end
113
+ end
87
114
 
88
115
  describe 'generated class with filter', 'when filter value is only simbol' do
89
116
  before do
90
- @class = @fixuture_base._define_fixture([:foo], :bar)
117
+ @class = @fixuture_base._define_fixture([:foo], [:bar])
91
118
  filter = {
92
119
  :foo => :to_s,
93
120
  :bar => :inspect,
94
121
  }
95
- @class_instance = @class.new([:foo], :bar, nil, filter)
122
+ @class_instance = @class.new(:foo, :bar, nil, filter)
96
123
  end
97
124
 
98
125
  it_should_behave_like 'generated_class'
@@ -101,17 +128,38 @@ describe Spec::Fixture::Base do
101
128
  @class_instance.foo.should == 'foo'
102
129
  @class_instance._input.should == 'foo'
103
130
  @class_instance.bar.should == ':bar'
131
+ @class_instance._expected.should == ':bar'
132
+ end
133
+ end
134
+
135
+ describe 'generated class with filter', 'when filter value is only a String that start from "."' do
136
+ before do
137
+ @class = @fixuture_base._define_fixture([:foo], [:bar])
138
+ filter = {
139
+ :foo => '.html_escape',
140
+ :bar => '.html_unescape',
141
+ }
142
+ @class_instance = @class.new(:foo, :bar, nil, filter)
143
+ end
144
+
145
+ it_should_behave_like 'generated_class'
146
+
147
+ it 'should be applyed filter with sending symbol to raw value' do
148
+ @class_instance.foo.should == 'foo'
149
+ @class_instance._input.should == 'foo'
150
+ @class_instance.bar.should == 'bar'
151
+ @class_instance._expected.should == 'bar'
104
152
  end
105
153
  end
106
154
 
107
155
  describe 'generated class with filter', 'when filter value with symbol array' do
108
156
  before do
109
- @class = @fixuture_base._define_fixture([:foo], :bar)
157
+ @class = @fixuture_base._define_fixture([:foo], [:bar])
110
158
  filter = {
111
159
  :foo => [ :to_s, :inspect ],
112
160
  :bar => [ :to_s, :capitalize, :to_sym ]
113
161
  }
114
- @class_instance = @class.new([:foo], :bar, nil, filter)
162
+ @class_instance = @class.new([:foo], [:bar], nil, filter)
115
163
  end
116
164
 
117
165
  it_should_behave_like 'generated_class'
@@ -120,17 +168,18 @@ describe Spec::Fixture::Base do
120
168
  @class_instance.foo.should == '"foo"'
121
169
  @class_instance._input.should == '"foo"'
122
170
  @class_instance.bar.should == :Bar
171
+ @class_instance._expected.should == :Bar
123
172
  end
124
173
  end
125
174
 
126
175
  describe 'generated class with filter', 'when filter value with Proc' do
127
176
  before do
128
- @class = @fixuture_base._define_fixture([:foo], :bar)
177
+ @class = @fixuture_base._define_fixture([:foo], [:bar])
129
178
  filter = {
130
179
  :foo => lambda {|val| val.to_s.capitalize.reverse },
131
180
  :bar => lambda {|val| val.to_s.size }
132
181
  }
133
- @class_instance = @class.new([:foo], :bar, nil, filter)
182
+ @class_instance = @class.new([:foo], [:bar], nil, filter)
134
183
  end
135
184
 
136
185
  it_should_behave_like 'generated_class'
@@ -138,7 +187,7 @@ describe Spec::Fixture::Base do
138
187
  it 'should be applyed filter with executing Proc' do
139
188
  @class_instance.foo.should == 'ooF'
140
189
  @class_instance._input.should == 'ooF'
141
- @class_instance.bar.should == 3
190
+ @class_instance._expected.should == 3
142
191
  end
143
192
  end
144
193
  end
@@ -39,8 +39,8 @@ describe Spec::Fixture::Base do
39
39
  @fxt.should_receive(:msg).and_return(nil)
40
40
  end
41
41
 
42
- it 'should return ""' do
43
- @fixture_base.generate_msg(@fxt).should == ""
42
+ it 'should return nil' do
43
+ @fixture_base.generate_msg(@fxt, nil).should be_nil
44
44
  end
45
45
  end
46
46
 
@@ -51,7 +51,7 @@ describe Spec::Fixture::Base do
51
51
  end
52
52
 
53
53
  it 'should return msg' do
54
- @fixture_base.generate_msg(@fxt).should == "fuga"
54
+ @fixture_base.generate_msg(@fxt, nil).should == "fuga"
55
55
  end
56
56
  end
57
57
 
@@ -70,14 +70,12 @@ describe Spec::Fixture::Base do
70
70
 
71
71
  it 'should convert :symbol to raw member inspect' do
72
72
  [:input, :expected].each do |member|
73
- @fixture_base.instance_variable_set('@desc_template', ":#{member}")
74
- @fixture_base.generate_msg(@fxt).should == '"raw value"'
73
+ @fixture_base.generate_msg(@fxt, ":#{member}").should == '"raw value"'
75
74
  end
76
75
  end
77
76
 
78
77
  it 'should convert :msg to fixture#msg value' do
79
- @fixture_base.instance_variable_set('@desc_template', ':msg')
80
- @fixture_base.generate_msg(@fxt).should == "fuga"
78
+ @fixture_base.generate_msg(@fxt, ':msg').should == "fuga"
81
79
  end
82
80
  end
83
81
 
@@ -101,14 +99,40 @@ describe Spec::Fixture::Base do
101
99
 
102
100
  it 'should convert :symbol to desc_filtered member value with sending symbol method to raw value' do
103
101
  [:input, :expected].each do |member|
104
- @fixture_base.instance_variable_set('@desc_template', ":#{member}")
105
- @fixture_base.generate_msg(@fxt).should == 'raw value'.upcase
102
+ @fixture_base.generate_msg(@fxt, ":#{member}").should == 'raw value'.upcase
103
+ end
104
+ end
105
+
106
+ it 'should convert :msg to fixture#msg value' do
107
+ @fixture_base.generate_msg(@fxt, ":msg").should == "fuga"
108
+ end
109
+ end
110
+
111
+ describe '#generate_msg' , "when @desc_template has value and @desc_filter_of has only a String that start from '.'" do
112
+ before do
113
+ @fxt = mock(:fixture)
114
+ @fxt.should_receive(:msg).any_number_of_times.and_return("fuga")
115
+ @fxt.should_receive(:_members).any_number_of_times.and_return([:input, :expected])
116
+ @fxt.should_receive(:value_of).any_number_of_times.and_return({
117
+ :input => "raw value",
118
+ :expected => "raw value",
119
+ })
120
+ @fxt.should_receive(:input).any_number_of_times.and_return("filtered value")
121
+ @fxt.should_receive(:expected).any_number_of_times.and_return("filtered value")
122
+ @fixture_base.instance_variable_set('@desc_filter_of', {
123
+ :input => '.html_escape',
124
+ :expected => '.html_unescape'
125
+ })
126
+ end
127
+
128
+ it 'should convert :symbol to desc_filtered member value with sending symbol method to raw value' do
129
+ [:input, :expected].each do |member|
130
+ @fixture_base.generate_msg(@fxt, ":#{member}").should == 'raw value'
106
131
  end
107
132
  end
108
133
 
109
134
  it 'should convert :msg to fixture#msg value' do
110
- @fixture_base.instance_variable_set('@desc_template', ':msg')
111
- @fixture_base.generate_msg(@fxt).should == "fuga"
135
+ @fixture_base.generate_msg(@fxt, ":msg").should == "fuga"
112
136
  end
113
137
  end
114
138
 
@@ -131,14 +155,12 @@ describe Spec::Fixture::Base do
131
155
 
132
156
  it 'should convert :symbol to desc_filtered member value with sending symbol method to raw value in array order' do
133
157
  [:input, :expected].each do |member|
134
- @fixture_base.instance_variable_set('@desc_template', ":#{member}")
135
- @fixture_base.generate_msg(@fxt).should == 'raw value'.upcase.reverse
158
+ @fixture_base.generate_msg(@fxt, ":#{member}").should == 'raw value'.upcase.reverse
136
159
  end
137
160
  end
138
161
 
139
162
  it 'should convert :msg to fixture#msg value' do
140
- @fixture_base.instance_variable_set('@desc_template', ':msg')
141
- @fixture_base.generate_msg(@fxt).should == "fuga"
163
+ @fixture_base.generate_msg(@fxt, ":msg").should == "fuga"
142
164
  end
143
165
  end
144
166
 
@@ -163,13 +185,12 @@ describe Spec::Fixture::Base do
163
185
  it 'should convert :symbol to desc_filtered member value with applying Proc result' do
164
186
  [:input, :expected].each do |member|
165
187
  @fixture_base.instance_variable_set('@desc_template', ":#{member}")
166
- @fixture_base.generate_msg(@fxt).should == @proc.call('raw value')
188
+ @fixture_base.generate_msg(@fxt, ":#{member}").should == @proc.call('raw value')
167
189
  end
168
190
  end
169
191
 
170
192
  it 'should convert :msg to fixture#msg value' do
171
- @fixture_base.instance_variable_set('@desc_template', ':msg')
172
- @fixture_base.generate_msg(@fxt).should == "fuga"
193
+ @fixture_base.generate_msg(@fxt, ":msg").should == "fuga"
173
194
  end
174
195
  end
175
196
 
@@ -10,77 +10,81 @@ end
10
10
  task :default => [:spec]
11
11
  task :test => [:spec]
12
12
  task :package => [:clean]
13
-
13
+ begin
14
14
  require 'spec/rake/spectask'
15
- Spec::Rake::SpecTask.new(:spec) do |t|
16
- t.spec_files = FileList['spec/**/*_spec.rb']
17
- t.spec_opts = ['--options', 'spec/spec.opts']
18
- t.warning = true
19
- t.libs << 'lib'
20
- t.rcov = true
21
- t.rcov_dir = 'doc/output/coverage'
22
- t.rcov_opts = ['--exclude', '/*,spec,\.autotest', '-i', 'lib/**/*']
23
- end
15
+ Spec::Rake::SpecTask.new(:spec) do |t|
16
+ t.spec_files = FileList['spec/**/*_spec.rb']
17
+ t.spec_opts = ['--options', 'spec/spec.opts']
18
+ t.warning = true
19
+ t.libs << 'lib'
20
+ # t.rcov = true
21
+ # t.rcov_dir = 'doc/output/coverage'
22
+ # t.rcov_opts = ['--exclude', '/*,spec,\.autotest', '-i', 'lib/**/*']
23
+ end
24
24
 
25
- desc "Heckle each module and class in turn"
26
- task :heckle => :spec do
27
- root_modules = HECKLE_ROOT_MODULES
28
- spec_files = FileList['spec/**/*_spec.rb']
29
-
30
- current_module, current_method = nil, nil
31
- heckle_caught_modules = Hash.new { |hash, key| hash[key] = [] }
32
- unhandled_mutations = 0
33
-
34
- root_modules.each do |root_module|
35
- IO.popen("heckle #{root_module} -t #{spec_files}") do |pipe|
36
- while line = pipe.gets
37
- line = line.chomp
38
-
39
- if line =~ /^\*\*\* ((?:\w+(?:::)?)+)#(\w+)/
40
- current_module, current_method = $1, $2
41
- elsif line == "The following mutations didn't cause test failures:"
42
- heckle_caught_modules[current_module] << current_method
43
- elsif line == "+++ mutation"
44
- unhandled_mutations += 1
25
+ desc "Heckle each module and class in turn"
26
+ task :heckle => :spec do
27
+ root_modules = HECKLE_ROOT_MODULES
28
+ spec_files = FileList['spec/**/*_spec.rb']
29
+
30
+ current_module, current_method = nil, nil
31
+ heckle_caught_modules = Hash.new { |hash, key| hash[key] = [] }
32
+ unhandled_mutations = 0
33
+
34
+ root_modules.each do |root_module|
35
+ IO.popen("heckle #{root_module} -t #{spec_files}") do |pipe|
36
+ while line = pipe.gets
37
+ line = line.chomp
38
+
39
+ if line =~ /^\*\*\* ((?:\w+(?:::)?)+)#(\w+)/
40
+ current_module, current_method = $1, $2
41
+ elsif line == "The following mutations didn't cause test failures:"
42
+ heckle_caught_modules[current_module] << current_method
43
+ elsif line == "+++ mutation"
44
+ unhandled_mutations += 1
45
+ end
46
+
47
+ puts line
45
48
  end
46
-
47
- puts line
48
49
  end
49
50
  end
50
- end
51
-
52
- if unhandled_mutations > 0
53
- error_message_lines = ["*************\n"]
54
-
55
- error_message_lines <<
56
- "Heckle found #{unhandled_mutations} " +
57
- "mutation#{"s" unless unhandled_mutations == 1} " +
58
- "that didn't cause spec violations\n"
59
-
60
- heckle_caught_modules.each do |mod, methods|
51
+ if unhandled_mutations > 0
52
+ error_message_lines = ["*************\n"]
53
+
61
54
  error_message_lines <<
62
- "#{mod} contains the following poorly-specified methods:"
63
- methods.each do |m|
64
- error_message_lines << " - #{m}"
55
+ "Heckle found #{unhandled_mutations} " +
56
+ "mutation#{"s" unless unhandled_mutations == 1} " +
57
+ "that didn't cause spec violations\n"
58
+
59
+ heckle_caught_modules.each do |mod, methods|
60
+ error_message_lines <<
61
+ "#{mod} contains the following poorly-specified methods:"
62
+ methods.each do |m|
63
+ error_message_lines << " - #{m}"
64
+ end
65
+ error_message_lines << ""
65
66
  end
66
- error_message_lines << ""
67
+
68
+ error_message_lines <<
69
+ "Get your act together and come back " +
70
+ "when your specs are doing their job!"
71
+
72
+ puts "*************"
73
+ raise error_message_lines.join("\n")
74
+ else
75
+ puts "Well done! Your code withstood a heckling."
67
76
  end
68
-
69
- error_message_lines <<
70
- "Get your act together and come back " +
71
- "when your specs are doing their job!"
72
-
73
- puts "*************"
74
- raise error_message_lines.join("\n")
75
- else
76
- puts "Well done! Your code withstood a heckling."
77
77
  end
78
+ rescue LoadError
78
79
  end
79
80
 
80
- require 'spec/rake/verify_rcov'
81
- RCov::VerifyTask.new(:rcov_veryfy) do |t|
82
- t.index_html = "doc/output/coverage/index.html"
83
- t.threshold = 100
81
+ begin
82
+ require 'spec/rake/verify_rcov'
83
+ RCov::VerifyTask.new(:rcov_veryfy) do |t|
84
+ t.index_html = "doc/output/coverage/index.html"
85
+ t.threshold = 100
86
+ end
87
+ rescue LoadError
84
88
  end
85
89
 
86
90
  task :install do
metadata CHANGED
@@ -1,33 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: rspec-fixture
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2008-02-11 00:00:00 +09:00
8
- summary: Test::Base like DSL for RSpec
9
- require_paths:
10
- - lib
11
- email: walf443 at gmail.com
12
- homepage: http://akasakarb.rubyforge.org
13
- rubyforge_project: akasakarb
14
- description: Test::Base like DSL for RSpec
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.0.2
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Keiji, Yoshimi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-14 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.0
24
+ version:
25
+ description: Test::Base like DSL for RSpec
26
+ email: walf443 at gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ - ChangeLog
31
34
  files:
32
35
  - Rakefile
33
36
  - README
@@ -38,6 +41,7 @@ files:
38
41
  - lib/spec/fixture/extentions
39
42
  - lib/spec/fixture/extentions/example
40
43
  - lib/spec/fixture/extentions/example/example_group_methods.rb
44
+ - lib/spec/fixture/filter.rb
41
45
  - lib/spec/fixture.rb
42
46
  - spec/spec-fixture-base-_define_fixture_spec.rb
43
47
  - spec/spec-fixture-base_spec.rb
@@ -47,10 +51,9 @@ files:
47
51
  - tasks/basic_config.rake
48
52
  - tasks/basic_tasks.rake
49
53
  - examples/detect_location_spec.rb
50
- test_files:
51
- - spec/spec-fixture-base-_define_fixture_spec.rb
52
- - spec/spec-fixture-base_spec.rb
53
- - spec/with_fixture_spec.rb
54
+ has_rdoc: true
55
+ homepage: http://akasakarb.rubyforge.org
56
+ post_install_message:
54
57
  rdoc_options:
55
58
  - --charset
56
59
  - utf-8
@@ -64,22 +67,28 @@ rdoc_options:
64
67
  - ^(example|extras)/
65
68
  - --title
66
69
  - rspec-fixture documentation
67
- extra_rdoc_files:
68
- - README
69
- - ChangeLog
70
- executables: []
71
-
72
- extensions: []
73
-
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ version:
74
84
  requirements: []
75
85
 
76
- dependencies:
77
- - !ruby/object:Gem::Dependency
78
- name: rspec
79
- version_requirement:
80
- version_requirements: !ruby/object:Gem::Version::Requirement
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- version: 1.0.0
85
- version:
86
+ rubyforge_project: akasakarb
87
+ rubygems_version: 1.3.0
88
+ signing_key:
89
+ specification_version: 2
90
+ summary: Test::Base like DSL for RSpec
91
+ test_files:
92
+ - spec/spec-fixture-base-_define_fixture_spec.rb
93
+ - spec/spec-fixture-base_spec.rb
94
+ - spec/with_fixture_spec.rb