rspec-fixture 0.0.1

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.
@@ -0,0 +1,63 @@
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
+ ----------------------------------------------------------------------
data/README ADDED
@@ -0,0 +1,50 @@
1
+
2
+ = rspec-fixture
3
+ Test::Base like DSL for RSpec
4
+
5
+ == Synopsis
6
+ require 'spec'
7
+ require 'spec/fixture'
8
+
9
+ describe Point, "detect_location" do
10
+ with_fixtures [:x, :y] => :location do
11
+ filters({
12
+ :location => [:to_s, ]
13
+ })
14
+
15
+ it 'should detect point (:x, :y) to :location (:msg)' do |input, location|
16
+ Point.new(input[:x], input[:y]).detect_location.should == location
17
+ end
18
+
19
+ set_fixtures([
20
+ [ [1, 0] => :right ],
21
+ [{[-1, 0] => :left }, "border" ],
22
+ [{[-0.5,0] => :left }, "inner" ],
23
+ [ [0, 1] => :top ],
24
+ [ [0, -1] => :bottom ],
25
+ ])
26
+ end
27
+ end
28
+
29
+ If you'd like to know more usage, see also files that is located under "example" directory and run it.
30
+
31
+ == Description
32
+ Test::Base is a perl testing library. It make you writing test simple and elegant with many data. RSpec is cool to write a test when it has many context, but it was too boring to write a simple testing with many data. So, I write this.
33
+
34
+ == Installation
35
+
36
+ === Archive Installation
37
+
38
+ rake install
39
+
40
+ === Gem Installation
41
+
42
+ gem install rspec-fixture
43
+
44
+ == Features/Problems
45
+
46
+ == Copyright
47
+
48
+ Author:: Keiji, Yoshimi <walf443 at gmail.com>
49
+ Copyright:: Copyright (c) 2008 Keiji, Yoshimi
50
+ License:: you can redistribute it and/or modify it under the same terms as Ruby itself.
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'rake/contrib/sshpublisher'
10
+ require 'fileutils'
11
+ include FileUtils
12
+
13
+ load File.join(File.dirname(__FILE__), 'tasks', 'basic_config.rake')
14
+
15
+ NAME = "rspec-fixture"
16
+ DESCRIPTION = <<-"END_DESCRIPTION"
17
+ Test::Base like DSL for RSpec
18
+ END_DESCRIPTION
19
+ BIN_FILES = %w( )
20
+ VERS = "0.0.1"
21
+ RUBYFORGE_PACKAGE_ID = 7007
22
+
23
+ EXTRA_RDOC_FILES = []
24
+ HECKLE_ROOT_MODULES = ["Spec::Fixture"]
25
+
26
+ SPEC = Gem::Specification.new do |s|
27
+ s.name = NAME
28
+ s.version = VERS
29
+ s.platform = Gem::Platform::RUBY
30
+ s.has_rdoc = true
31
+ s.extra_rdoc_files = DEFAULT_EXTRA_RDOC_FILES + EXTRA_RDOC_FILES
32
+ s.rdoc_options += RDOC_OPTS + ['--title', "#{NAME} documentation"]
33
+ s.summary = DESCRIPTION
34
+ s.description = DESCRIPTION
35
+ s.author = AUTHOR
36
+ s.email = EMAIL
37
+ s.homepage = HOMEPATH
38
+ s.executables = BIN_FILES
39
+ s.rubyforge_project = RUBYFORGE_PROJECT
40
+ s.bindir = "bin"
41
+ s.require_path = "lib"
42
+ s.test_files = Dir["spec/*_spec.rb"]
43
+
44
+ #s.add_dependency('activesupport', '>=1.3.1')
45
+ #s.required_ruby_version = '>= 1.8.2'
46
+ s.add_dependency('rspec', '>= 1.0.0')
47
+
48
+ s.files = PKG_FILES + EXTRA_RDOC_FILES
49
+ s.extensions = EXTENSIONS
50
+ end
51
+
52
+ import File.join(File.dirname(__FILE__), 'tasks', 'basic_tasks.rake')
@@ -0,0 +1,84 @@
1
+ require 'spec'
2
+ require File.expand_path(File.join(File.dirname(__FILE__), '../lib/spec/fixture'))
3
+
4
+ class Point
5
+ def initialize x, y
6
+ @x, @y = x, y
7
+ end
8
+
9
+ def detect_location
10
+ return 'unknown'
11
+ end
12
+
13
+ def to_s
14
+ "( #@x, #@y )"
15
+ end
16
+ end
17
+
18
+ describe Point, "detect_location" do
19
+ with_fixtures [:x, :y] => :location do
20
+ filters({
21
+ :location => [:to_s, ]
22
+ })
23
+
24
+ it 'should detect point (:x, :y) to :location (:msg)' do |input, location|
25
+ Point.new(input[:x], input[:y]).detect_location.should == location
26
+ end
27
+
28
+ set_fixtures([
29
+ [ [1, 0] => :right ],
30
+ [{[-1, 0] => :left }, "border" ],
31
+ [{[-0.5,0] => :left }, "inner" ],
32
+ [ [0, 1] => :top ],
33
+ [ [0, -1] => :bottom ],
34
+ ])
35
+ end
36
+ end
37
+
38
+ # you can also write following.
39
+ describe Point, "detect_location" do
40
+ with_fixtures :point => :location do
41
+ filters({
42
+ :point => lambda { |val| Point.new(*val).detect_location },
43
+ :location => :to_s,
44
+ })
45
+
46
+ it "should detect point :point to :location :msg" do |point, location|
47
+ point.should == location
48
+ end
49
+
50
+ set_fixtures([
51
+ [ [1, 0] => :right ],
52
+ [{[-1, 0] => :left }, "(border case)" ],
53
+ [{[-0.5,0] => :left }, "(inner case)" ],
54
+ [ [0, 1] => :top ],
55
+ [ [0, -1] => :bottom ],
56
+ ])
57
+ end
58
+ end
59
+
60
+ # If you skip with_fixtures argments, { :input => :expected } was use as default
61
+ describe Point, "detect_location" do
62
+ with_fixtures do
63
+ filters({
64
+ :input => lambda {|val| Point.new(*val).detect_location },
65
+ :expected => :to_s,
66
+ })
67
+
68
+ desc_filters({
69
+ :input => lambda {|val| "(#{val.join(', ')})" }
70
+ })
71
+
72
+ it "should detect point :input to :expected :msg" do |input, expected|
73
+ input.should == expected
74
+ end
75
+
76
+ set_fixtures([
77
+ [ [1, 0] => :right ],
78
+ [{[-1, 0] => :left }, "(border case)" ],
79
+ [{[-0.5,0] => :left }, "(inner case)" ],
80
+ [ [0, 1] => :top ],
81
+ [ [0, -1] => :bottom ],
82
+ ])
83
+ end
84
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '../')))
4
+
5
+ module Spec
6
+ module Fixture
7
+ end
8
+ end
9
+
10
+ require 'spec/fixture/base'
11
+ require 'spec/fixture/extentions/example/example_group_methods'
@@ -0,0 +1,168 @@
1
+ class Spec::Fixture::Base
2
+ attr_reader :fixtures, :desc_template, :example_shared_runner
3
+
4
+ def initialize binding, hash, &block
5
+ @binding = binding
6
+ input_names, expected_name = *hash.to_a.first
7
+ unless input_names.kind_of? Array
8
+ input_names = [ input_names ]
9
+ end
10
+ _define_fixture(input_names, expected_name)
11
+ instance_eval(&block)
12
+ end
13
+
14
+ # This &example block was iterate as example by each fixture.
15
+ # when you specify description for example,
16
+ # you can use ":" started string as template variable.
17
+ # Template variable is expand to raw value's inspect in default
18
+ # expect for :msg. If you customize output message,
19
+ # please use +desc_filters+.
20
+ #
21
+ # 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.
24
+ def it desc=nil, &example
25
+ if desc
26
+ @desc_template = desc
27
+ end
28
+ @example_shared_runner = example
29
+ end
30
+
31
+ # You specify test data in this methods.
32
+ # Argument should be Array that has a Hash (and string optionaly).
33
+ # In Hasy key, you write input data and in its value you write expected data.
34
+ def set_fixtures data
35
+ @fixtures = data.map do |item|
36
+ fxt, msg = *item
37
+ input, expected = *fxt.to_a.first
38
+ @class.new input, expected, msg, @filter_of
39
+ end
40
+ end
41
+
42
+ # If you specify +filters+, you can use filtered value in +it+'s block
43
+ # filters argument is hash that has a key of members.
44
+ # value should be string or symbol or Array that contain strings or symbols or Proc.
45
+ # 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.
48
+ def filters hash
49
+ @filter_of = hash
50
+ end
51
+
52
+ # If you customize specify for example, you should use this method.
53
+ # This methods's usage is the same as +filters+.
54
+ def desc_filters hash
55
+ @desc_filter_of = hash
56
+ end
57
+
58
+ def generate_msg fxt #:nodoc:
59
+ if @desc_template
60
+ msg = @desc_template
61
+ [ fxt._members, :msg ].flatten.each do |item|
62
+ if item == :msg
63
+ result = fxt.msg.to_s
64
+ else
65
+ result = fxt.value_of[item]
66
+ if @desc_filter_of && @desc_filter_of[item]
67
+ if @desc_filter_of[item].kind_of? Proc
68
+ result = @desc_filter_of[item].call(result)
69
+ else
70
+ [ @desc_filter_of[item] ].flatten.each do |meth|
71
+ result = result.__send__ meth
72
+ end
73
+ end
74
+ else
75
+ result = result.inspect
76
+ end
77
+ end
78
+ msg = msg.gsub(/:#{item.to_s}/, result)
79
+ end
80
+
81
+ msg
82
+ else
83
+ if fxt.msg
84
+ fxt.msg
85
+ else
86
+ ""
87
+ end
88
+ end
89
+ end
90
+
91
+ def run #:nodoc:
92
+ fixture = self
93
+ @binding.module_eval do
94
+ if fixture.fixtures
95
+ fixture.fixtures.each do |fxt|
96
+ it fixture.generate_msg(fxt) do
97
+ fixture.example_shared_runner.call(fxt._input, fxt._expected)
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ # generate temp class for fixture.
105
+ def _define_fixture input, expected #:nodoc:
106
+ klass = Class.new
107
+ klass.class_eval do
108
+ attr_reader :filter_of, :value_of, :msg
109
+
110
+ define_method :initialize do |_input, _expected, msg, filter_of|
111
+ @value_of = {}
112
+ @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
119
+ end
120
+ end
121
+ @value_of[expected] = _expected
122
+ @msg = msg
123
+ end
124
+
125
+ define_method :_members do
126
+ [ input, expected].flatten
127
+ end
128
+
129
+ define_method :_expected do
130
+ __send__ expected
131
+ end
132
+
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
140
+ end
141
+
142
+ result_of
143
+ end
144
+ end
145
+
146
+ [ input, expected ].flatten.each do |item|
147
+ raise NameError if instance_methods.map{|i| i.to_s }.include? item.to_s
148
+
149
+ define_method item do
150
+ result = @value_of[item]
151
+ if @filter_of[item].kind_of? Proc
152
+ result = @filter_of[item].call(result)
153
+ else
154
+ if @filter_of[item]
155
+ [ @filter_of[item] ].flatten.each do |filter|
156
+ result = result.__send__ filter
157
+ end
158
+ end
159
+ end
160
+
161
+ result
162
+ end
163
+ end
164
+ end
165
+
166
+ @class = klass
167
+ end
168
+ end
@@ -0,0 +1,17 @@
1
+ module Spec
2
+ module Fixture
3
+ module Extentions
4
+ module Example
5
+ module ExampleGroupMethods
6
+ def with_fixtures hash={ :input => :expected }, &fixture_block
7
+ Spec::Fixture::Base.new(self, hash, &fixture_block).run
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ Spec::ExampleGroup.instance_eval do
16
+ extend Spec::Fixture::Extentions::Example::ExampleGroupMethods
17
+ end
@@ -0,0 +1,145 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ shared_examples_for 'generated_class' do
4
+ # reserverd methods
5
+ %w(_input _expected _members filter_of value_of msg).each do |method|
6
+ it "should have #{method} instance method" do
7
+ @class.instance_methods.map {|i| i.to_s }.should include(method)
8
+ end
9
+ end
10
+
11
+ it "should have instance method in each members" do
12
+ @class_instance._members.each do |member|
13
+ @class.instance_methods.map {|i| i.to_s }.should include(member.to_s)
14
+ end
15
+ end
16
+
17
+ end
18
+
19
+ describe Spec::Fixture::Base do
20
+ describe '#_define_fixture' do
21
+ before do
22
+ @fixuture_base = Spec::Fixture::Base.allocate
23
+ end
24
+
25
+ it 'should generate some class' do
26
+ @fixuture_base._define_fixture(:foo, :bar).should be_kind_of(Class)
27
+ end
28
+
29
+ %w(_input _expected _members filter_of value_of msg).each do |reserved_name|
30
+ it "should raise NameError when using #{reserved_name} for arguments" do
31
+ lambda {
32
+ @fixuture_base._define_fixture(reserved_name, :foo)
33
+ }.should raise_error(NameError)
34
+ end
35
+ end
36
+
37
+ it 'should raise NameError when specify same name for arguments' do
38
+ lambda {
39
+ @fixuture_base._define_fixture([:foo], :foo)
40
+ }.should raise_error(NameError)
41
+ end
42
+
43
+ describe 'generated class', 'when one input, one expected' do
44
+ before do
45
+ @class = @fixuture_base._define_fixture([:foo], :bar)
46
+ @class_instance = @class.new([:foo], :bar, nil, nil)
47
+ end
48
+
49
+ it_should_behave_like 'generated_class'
50
+
51
+ it 'should have members list' do
52
+ @class_instance._members.should == [:foo, :bar]
53
+ end
54
+
55
+ it 'should return same value between expected member and _expected method' do
56
+ @class_instance._expected.should == @class_instance.bar
57
+ end
58
+
59
+ it 'should return same value between input member and _input method' do
60
+ @class_instance._input.should == @class_instance.foo
61
+ end
62
+ end
63
+
64
+ describe 'generated class', 'when two input, one expected' do
65
+ before do
66
+ @class = @fixuture_base._define_fixture([:foo, :bar], :baz)
67
+ @class_instance = @class.new([:foo, :bar], :baz, nil, nil)
68
+ end
69
+
70
+ it_should_behave_like 'generated_class'
71
+
72
+ it 'should have members list' do
73
+ @class_instance._members.should == [:foo, :bar, :baz]
74
+ end
75
+
76
+ it 'should return same value between expected member and _expected method' do
77
+ @class_instance._expected.should == @class_instance.baz
78
+ end
79
+
80
+ it '_input method should return input members method result Hash' do
81
+ @class_instance._input.should == {
82
+ :foo => @class_instance.foo,
83
+ :bar => @class_instance.bar
84
+ }
85
+ end
86
+ end
87
+
88
+ describe 'generated class with filter', 'when filter value is only simbol' do
89
+ before do
90
+ @class = @fixuture_base._define_fixture([:foo], :bar)
91
+ filter = {
92
+ :foo => :to_s,
93
+ :bar => :inspect,
94
+ }
95
+ @class_instance = @class.new([:foo], :bar, nil, filter)
96
+ end
97
+
98
+ it_should_behave_like 'generated_class'
99
+
100
+ it 'should be applyed filter with sending symbol to raw value' do
101
+ @class_instance.foo.should == 'foo'
102
+ @class_instance._input.should == 'foo'
103
+ @class_instance.bar.should == ':bar'
104
+ end
105
+ end
106
+
107
+ describe 'generated class with filter', 'when filter value with symbol array' do
108
+ before do
109
+ @class = @fixuture_base._define_fixture([:foo], :bar)
110
+ filter = {
111
+ :foo => [ :to_s, :inspect ],
112
+ :bar => [ :to_s, :capitalize, :to_sym ]
113
+ }
114
+ @class_instance = @class.new([:foo], :bar, nil, filter)
115
+ end
116
+
117
+ it_should_behave_like 'generated_class'
118
+
119
+ it 'should be applyed filter with sending symbol in order array to raw value' do
120
+ @class_instance.foo.should == '"foo"'
121
+ @class_instance._input.should == '"foo"'
122
+ @class_instance.bar.should == :Bar
123
+ end
124
+ end
125
+
126
+ describe 'generated class with filter', 'when filter value with Proc' do
127
+ before do
128
+ @class = @fixuture_base._define_fixture([:foo], :bar)
129
+ filter = {
130
+ :foo => lambda {|val| val.to_s.capitalize.reverse },
131
+ :bar => lambda {|val| val.to_s.size }
132
+ }
133
+ @class_instance = @class.new([:foo], :bar, nil, filter)
134
+ end
135
+
136
+ it_should_behave_like 'generated_class'
137
+
138
+ it 'should be applyed filter with executing Proc' do
139
+ @class_instance.foo.should == 'ooF'
140
+ @class_instance._input.should == 'ooF'
141
+ @class_instance.bar.should == 3
142
+ end
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,178 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Spec::Fixture::Base do
4
+ describe '#initialize' do
5
+ %w(it set_fixtures filter generate_msg).each do |method|
6
+ it "should be able to use #{method} in block" do
7
+ Spec::Fixture::Base.new(binding, {:input => :expected }) do
8
+ method
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ before do
15
+ @fixture_base = Spec::Fixture::Base.new(binding, {:input => :expected }) do
16
+ end
17
+ end
18
+
19
+ describe '#set_fixtures' do
20
+ it 'should convert each data to generated class instance' do
21
+ @fixture_base.set_fixtures([
22
+ [ {:input => :expected}, :msg ]
23
+ ]).each do |fixture|
24
+ fixture.should_not be_kind_of(Array)
25
+ %w(_input _expected _members msg value_of filter_of).each do |reserved_meth|
26
+ fixture.methods.should include(reserved_meth)
27
+ end
28
+
29
+ %w(input expected).each do |member|
30
+ fixture.methods.should include(member)
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '#generate_msg' , "when @desc_template is nil and fixture don't have msg" do
37
+ before do
38
+ @fxt = mock(:fixture)
39
+ @fxt.should_receive(:msg).and_return(nil)
40
+ end
41
+
42
+ it 'should return ""' do
43
+ @fixture_base.generate_msg(@fxt).should == ""
44
+ end
45
+ end
46
+
47
+ describe '#generate_msg' , "when @desc_template is nil and fixture have msg" do
48
+ before do
49
+ @fxt = mock(:fixture)
50
+ @fxt.should_receive(:msg).any_number_of_times.and_return("fuga")
51
+ end
52
+
53
+ it 'should return msg' do
54
+ @fixture_base.generate_msg(@fxt).should == "fuga"
55
+ end
56
+ end
57
+
58
+ describe '#generate_msg' , "when @desc_template has value and @desc_filter_of has not value" do
59
+ before do
60
+ @fxt = mock(:fixture)
61
+ @fxt.should_receive(:msg).any_number_of_times.and_return("fuga")
62
+ @fxt.should_receive(:_members).any_number_of_times.and_return([:input, :expected])
63
+ @fxt.should_receive(:value_of).any_number_of_times.and_return({
64
+ :input => "raw value",
65
+ :expected => "raw value",
66
+ })
67
+ @fxt.should_receive(:input).any_number_of_times.and_return("filtered value")
68
+ @fxt.should_receive(:expected).any_number_of_times.and_return("filtered value")
69
+ end
70
+
71
+ it 'should convert :symbol to raw member inspect' do
72
+ [:input, :expected].each do |member|
73
+ @fixture_base.instance_variable_set('@desc_template', ":#{member}")
74
+ @fixture_base.generate_msg(@fxt).should == '"raw value"'
75
+ end
76
+ end
77
+
78
+ 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"
81
+ end
82
+ end
83
+
84
+
85
+ describe '#generate_msg' , "when @desc_template has value and @desc_filter_of has :symbol value" do
86
+ before do
87
+ @fxt = mock(:fixture)
88
+ @fxt.should_receive(:msg).any_number_of_times.and_return("fuga")
89
+ @fxt.should_receive(:_members).any_number_of_times.and_return([:input, :expected])
90
+ @fxt.should_receive(:value_of).any_number_of_times.and_return({
91
+ :input => "raw value",
92
+ :expected => "raw value",
93
+ })
94
+ @fxt.should_receive(:input).any_number_of_times.and_return("filtered value")
95
+ @fxt.should_receive(:expected).any_number_of_times.and_return("filtered value")
96
+ @fixture_base.instance_variable_set('@desc_filter_of', {
97
+ :input => :upcase,
98
+ :expected => :upcase
99
+ })
100
+ end
101
+
102
+ it 'should convert :symbol to desc_filtered member value with sending symbol method to raw value' do
103
+ [:input, :expected].each do |member|
104
+ @fixture_base.instance_variable_set('@desc_template', ":#{member}")
105
+ @fixture_base.generate_msg(@fxt).should == 'raw value'.upcase
106
+ end
107
+ end
108
+
109
+ 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"
112
+ end
113
+ end
114
+
115
+ describe '#generate_msg' , "when @desc_template has value and @desc_filter_of has :symbol array" do
116
+ before do
117
+ @fxt = mock(:fixture)
118
+ @fxt.should_receive(:msg).any_number_of_times.and_return("fuga")
119
+ @fxt.should_receive(:_members).any_number_of_times.and_return([:input, :expected])
120
+ @fxt.should_receive(:value_of).any_number_of_times.and_return({
121
+ :input => "raw value",
122
+ :expected => "raw value",
123
+ })
124
+ @fxt.should_receive(:input).any_number_of_times.and_return("filtered value")
125
+ @fxt.should_receive(:expected).any_number_of_times.and_return("filtered value")
126
+ @fixture_base.instance_variable_set('@desc_filter_of', {
127
+ :input => [ :upcase, :reverse ],
128
+ :expected => [ :upcase, :reverse ],
129
+ })
130
+ end
131
+
132
+ it 'should convert :symbol to desc_filtered member value with sending symbol method to raw value in array order' do
133
+ [: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
136
+ end
137
+ end
138
+
139
+ 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"
142
+ end
143
+ end
144
+
145
+ describe '#generate_msg' , "when @desc_template has value and @desc_filter_of has Proc value" do
146
+ before do
147
+ @fxt = mock(:fixture)
148
+ @fxt.should_receive(:msg).any_number_of_times.and_return("fuga")
149
+ @fxt.should_receive(:_members).any_number_of_times.and_return([:input, :expected])
150
+ @fxt.should_receive(:value_of).any_number_of_times.and_return({
151
+ :input => "raw value",
152
+ :expected => "raw value",
153
+ })
154
+ @fxt.should_receive(:input).any_number_of_times.and_return("filtered value")
155
+ @fxt.should_receive(:expected).any_number_of_times.and_return("filtered value")
156
+ @proc = lambda {|val| val.upcase.reverse }
157
+ @fixture_base.instance_variable_set('@desc_filter_of', {
158
+ :input => @proc,
159
+ :expected => @proc,
160
+ })
161
+ end
162
+
163
+ it 'should convert :symbol to desc_filtered member value with applying Proc result' do
164
+ [:input, :expected].each do |member|
165
+ @fixture_base.instance_variable_set('@desc_template', ":#{member}")
166
+ @fixture_base.generate_msg(@fxt).should == @proc.call('raw value')
167
+ end
168
+ end
169
+
170
+ 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"
173
+ end
174
+ end
175
+
176
+ describe '#run' do
177
+ end
178
+ end
@@ -0,0 +1 @@
1
+ -Du -c -fs
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib/'))
4
+ require 'spec/fixture'
5
+
@@ -0,0 +1,32 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe 'with_fixtures' do
4
+ it 'should defined in example group scope' do
5
+ lambda do
6
+ describe 'testing' do
7
+ with_fixtures do
8
+ end
9
+ end
10
+ end.should_not raise_error
11
+ end
12
+
13
+ it 'should work well in nested example groups' do
14
+ lambda do
15
+ describe 'foo' do
16
+ describe 'bar' do
17
+ with_fixtures do
18
+ end
19
+ end
20
+ end
21
+ end.should_not raise_error
22
+ end
23
+
24
+ it "should not defined in Kernel scope" do
25
+ lambda do
26
+ Kernel.instanse_eval do
27
+ with_fixtures do
28
+ end
29
+ end
30
+ end.should raise_error(NoMethodError)
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+ AUTHOR = "Keiji, Yoshimi"
2
+ EMAIL = "walf443 at gmail.com"
3
+ RUBYFORGE_PROJECT = "akasakarb"
4
+ RUBYFORGE_PROJECT_ID = 4314
5
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
6
+ RDOC_OPTS = [
7
+ "--charset", "utf-8",
8
+ "--opname", "index.html",
9
+ "--line-numbers",
10
+ "--main", "README",
11
+ "--inline-source",
12
+ '--exclude', '^(example|extras)/'
13
+ ]
14
+ DEFAULT_EXTRA_RDOC_FILES = ['README', 'ChangeLog']
15
+ PKG_FILES = [ 'Rakefile' ] +
16
+ DEFAULT_EXTRA_RDOC_FILES +
17
+ Dir.glob('{bin,lib,test,spec,doc,tasks,script,generator,templates,extras,website}/**/*') +
18
+ Dir.glob('ext/**/*.{h,c,rb}') +
19
+ Dir.glob('examples/**/*.rb') +
20
+ Dir.glob('tools/*.rb')
21
+
22
+ EXTENSIONS = FileList['ext/**/extconf.rb'].to_a
@@ -0,0 +1,140 @@
1
+
2
+ REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
3
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config']
4
+
5
+ Rake::GemPackageTask.new(SPEC) do |p|
6
+ p.need_tar = true
7
+ p.gem_spec = SPEC
8
+ end
9
+
10
+ task :default => [:spec]
11
+ task :test => [:spec]
12
+ task :package => [:clean]
13
+
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
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
45
+ end
46
+
47
+ puts line
48
+ end
49
+ 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|
61
+ error_message_lines <<
62
+ "#{mod} contains the following poorly-specified methods:"
63
+ methods.each do |m|
64
+ error_message_lines << " - #{m}"
65
+ end
66
+ error_message_lines << ""
67
+ 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
+ end
78
+ end
79
+
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
84
+ end
85
+
86
+ task :install do
87
+ name = "#{NAME}-#{VERS}.gem"
88
+ sh %{rake package}
89
+ sh %{sudo gem install pkg/#{name}}
90
+ end
91
+
92
+ task :uninstall => [:clean] do
93
+ sh %{sudo gem uninstall #{NAME}}
94
+ end
95
+
96
+
97
+ Rake::RDocTask.new do |rdoc|
98
+ rdoc.rdoc_dir = 'html'
99
+ rdoc.options += RDOC_OPTS
100
+ rdoc.template = "resh"
101
+ #rdoc.template = "#{ENV['template']}.rb" if ENV['template']
102
+ if ENV['DOC_FILES']
103
+ rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
104
+ else
105
+ rdoc.rdoc_files.include('README', 'ChangeLog')
106
+ rdoc.rdoc_files.include('lib/**/*.rb')
107
+ rdoc.rdoc_files.include('ext/**/*.c')
108
+ end
109
+ end
110
+
111
+ desc "Publish to RubyForge"
112
+ task :rubyforge => [:rdoc, :package] do
113
+ require 'rubyforge'
114
+ Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'yoshimi').upload
115
+ end
116
+
117
+ desc 'Package and upload the release to rubyforge.'
118
+ task :release => [:clean, :package] do |t|
119
+ require 'rubyforge'
120
+ v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
121
+ abort "Versions don't match #{v} vs #{VERS}" unless v == VERS
122
+ pkg = "pkg/#{NAME}-#{VERS}"
123
+
124
+ rf = RubyForge.new
125
+ puts "Logging in"
126
+ rf.login
127
+
128
+ c = rf.userconfig
129
+ # c["release_notes"] = description if description
130
+ # c["release_changes"] = changes if changes
131
+ c["preformatted"] = true
132
+
133
+ files = [
134
+ "#{pkg}.tgz",
135
+ "#{pkg}.gem"
136
+ ].compact
137
+
138
+ puts "Releasing #{NAME} v. #{VERS}"
139
+ rf.add_release RUBYFORGE_PROJECT_ID, RUBYFORGE_PACKAGE_ID, VERS, *files
140
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: rspec-fixture
5
+ 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:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Keiji, Yoshimi
31
+ files:
32
+ - Rakefile
33
+ - README
34
+ - ChangeLog
35
+ - lib/spec
36
+ - lib/spec/fixture
37
+ - lib/spec/fixture/base.rb
38
+ - lib/spec/fixture/extentions
39
+ - lib/spec/fixture/extentions/example
40
+ - lib/spec/fixture/extentions/example/example_group_methods.rb
41
+ - lib/spec/fixture.rb
42
+ - spec/spec-fixture-base-_define_fixture_spec.rb
43
+ - spec/spec-fixture-base_spec.rb
44
+ - spec/spec.opts
45
+ - spec/spec_helper.rb
46
+ - spec/with_fixture_spec.rb
47
+ - tasks/basic_config.rake
48
+ - tasks/basic_tasks.rake
49
+ - 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
+ rdoc_options:
55
+ - --charset
56
+ - utf-8
57
+ - --opname
58
+ - index.html
59
+ - --line-numbers
60
+ - --main
61
+ - README
62
+ - --inline-source
63
+ - --exclude
64
+ - ^(example|extras)/
65
+ - --title
66
+ - rspec-fixture documentation
67
+ extra_rdoc_files:
68
+ - README
69
+ - ChangeLog
70
+ executables: []
71
+
72
+ extensions: []
73
+
74
+ requirements: []
75
+
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: