ratnikov-shoulda 2.0.6.2 → 2.0.6.3

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.
data/Rakefile CHANGED
@@ -45,15 +45,15 @@ spec = Gem::Specification.new do |s|
45
45
  s.homepage = "http://thoughtbot.com/projects/shoulda"
46
46
  s.rubyforge_project = "shoulda"
47
47
 
48
- s.files = FileList["[A-Z]*", "{bin,lib,rails,test}/**/*"]
48
+ s.files = FileList["[A-Z]*", "{bin,lib,rails,test,tasks}/**/*"] + ['init.rb']
49
49
  s.executables = s.files.grep(/^bin/) { |f| File.basename(f) }
50
50
 
51
51
  s.has_rdoc = true
52
52
  s.extra_rdoc_files = ["README.rdoc", "CONTRIBUTION_GUIDELINES.rdoc"]
53
53
  s.rdoc_options = ["--line-numbers", "--inline-source", "--main", "README.rdoc"]
54
54
 
55
- s.authors = ["Tammer Saleh"]
56
- s.email = "tsaleh@thoughtbot.com"
55
+ s.authors = ["Tammer Saleh", "Dmitry Ratnikov"]
56
+ s.email = "ratnikov@gmail.com"
57
57
  end
58
58
 
59
59
  Rake::GemPackageTask.new spec do |pkg|
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'rails', 'init')
@@ -1,3 +1,5 @@
1
+ require 'shoulda/multiple_contexts'
2
+
1
3
  module Shoulda
2
4
  class << self
3
5
  attr_accessor :contexts
@@ -170,6 +172,8 @@ module Shoulda
170
172
  context.build
171
173
  end
172
174
  end
175
+
176
+ include MultipleContexts
173
177
  end
174
178
 
175
179
  class Context # :nodoc:
@@ -0,0 +1,76 @@
1
+ module Shoulda
2
+ module MultipleContexts
3
+ # == Multiple Contexts Support
4
+ #
5
+ # This module allows specifying a block of shoulda statements to be executed within multiple contexts.
6
+ # The rationale of the approach is to allow validation of identical behavior within different contexts.
7
+ #
8
+ # === Example:
9
+ #
10
+ # class FooTest
11
+ # class << self
12
+ # def with_string &block
13
+ # context "with foo" do
14
+ # setup { @foo = :foo }
15
+ # instance_exec &block
16
+ # end
17
+ #
18
+ # def with_symbol &block
19
+ # context "with foo" do
20
+ # setup { @foo = "bar" }
21
+ # instance_exec &block
22
+ # end
23
+ # end
24
+ #
25
+ # with_string_or_symbol do
26
+ # context "#to_my_string"
27
+ # evaluate { @to_my_string = @foo.to_my_string }
28
+ # should("be same as #to_s) { assert_equal @foo.to_s, @to_my_string }
29
+ # end
30
+ # end
31
+ # end
32
+ #
33
+ # ...will produce following tests:
34
+ # * <tt>"test: with string #to_my_string should be same as #to_s. "</tt>
35
+ # * <tt>"test: with symbol #to_my_string should be same as #to_s. "</tt>
36
+ #
37
+ # === NOTE
38
+ #
39
+ # Current implementation relies on following convention of custom context naming:
40
+ # * name of the method has to start with <tt>with_</tt> .
41
+ # * name should not contain <tt>_or_</tt>.
42
+ #
43
+ # When defining custom context, you need to make sure to invoke <tt>instance_exec &block</tt> to invoke the
44
+ # customization block within the newly defined context.
45
+
46
+ def self.included base
47
+ base.class_eval do
48
+ alias method_missing_without_multiple_contexts method_missing
49
+ alias method_missing method_missing_with_multiple_contexts
50
+ end
51
+ end
52
+
53
+ def conditional_contexts context_names, block
54
+ context_names.each do |context_name|
55
+ send "with_#{context_name}", &block
56
+ end
57
+ end
58
+
59
+ def method_missing_with_multiple_contexts method, *args, &block
60
+ if method.to_s =~ multiple_contexts_method_regex
61
+ raise "Block missing" if block.blank?
62
+ context_names = $1.split(/_or_/)
63
+ conditional_contexts context_names, block
64
+ else
65
+ method_missing_without_multiple_contexts method, *args, &block
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ def multiple_contexts_method_regex
72
+ context_mask = '[a-zA-Z]\w*'
73
+ /^with_(#{context_mask}(?:_or_#{context_mask})+)$/
74
+ end
75
+ end
76
+ end
data/lib/shoulda.rb CHANGED
@@ -6,7 +6,7 @@ require 'shoulda/helpers'
6
6
  require 'shoulda/rails' if defined? RAILS_ROOT
7
7
 
8
8
  module Shoulda
9
- VERSION = "2.0.6"
9
+ VERSION = "2.0.6.3"
10
10
  end
11
11
 
12
12
  module Test # :nodoc: all
@@ -0,0 +1 @@
1
+ load File.join(File.dirname(__FILE__), "..", "lib", "shoulda", "tasks.rb")
@@ -0,0 +1,110 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class MultipleContextsTest < Test::Unit::TestCase
4
+ include Shoulda::MultipleContexts
5
+
6
+ class << self
7
+ def should_match_regex string, *groups
8
+ context "matching #{string.inspect}" do
9
+ should("match") { assert_match @regex, string }
10
+
11
+ unless groups.blank?
12
+ context "should capture groups #{groups.inspect}" do
13
+ evaluate { @captures = @regex.match(string).captures }
14
+ should("match expected group values") do
15
+ assert_equal groups, @captures
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ def should_not_match_regex string
23
+ should "not match #{string.inspect}" do
24
+ assert_no_match @regex, string
25
+ end
26
+ end
27
+ end
28
+
29
+ should "pass truthitest" do
30
+ assert true
31
+ end
32
+
33
+ context "#with_contexts_method_regex" do
34
+ evaluate { @regex = with_contexts_method_regex }
35
+ end
36
+
37
+ context "#method_missing_with_multiple_contexts" do
38
+ setup do
39
+ stubs(:conditional_contexts).with { |contexts, block| @conditional_contexts, @conditional_block = contexts, block }.returns :conditional_contexts
40
+ @block = proc { }
41
+ end
42
+ evaluate { assert_equal :conditional_contexts, method_missing_with_multiple_contexts(@method_name, &@block) }
43
+
44
+ context "for 'with_foo_or_bar'" do
45
+ setup { @method_name = "with_foo_or_bar" }
46
+ should "recognize the contexts" do
47
+ assert_equal ["foo", "bar"], @conditional_contexts
48
+ end
49
+
50
+ should("forward the block") { assert_equal @block, @conditional_block }
51
+ end
52
+ end
53
+
54
+ context "#conditional_contexts" do
55
+ setup do
56
+ @block = proc { }
57
+ end
58
+ evaluate { conditional_contexts @contexts, @block }
59
+
60
+ context "with a single context" do
61
+ setup do
62
+ @contexts = [ "foo" ]
63
+ stubs(:with_foo).with { |*args| @with_foo_args = args }.yields :with_foo
64
+ end
65
+ should "invoke 'with_foo'" do
66
+ assert_equal [], @with_foo_args
67
+ end
68
+ end
69
+
70
+ context "with two contexts" do
71
+ setup do
72
+ @contexts = ['foo', 'bar_zeta']
73
+ stubs(:with_foo).with { @with_foo_invoked = true }.yields :with_foo
74
+ stubs(:with_bar_zeta).with { @with_bar_zeta_invoked = true }.yields :with_bar_zeta
75
+ end
76
+ should("invoke 'with_foo'") { assert @with_foo_invoked, 'with_foo should have been invoked' }
77
+ should("invoke 'with_bar_zeta'") { assert @with_bar_zeta_invoked, 'with_bar_zeta should have been invoked' }
78
+ end
79
+ end
80
+
81
+ context "#multiple_contexts_method_regex" do
82
+ setup { @regex = multiple_contexts_method_regex }
83
+ should_match_regex "with_foo_or_bar", 'foo_or_bar'
84
+ should_not_match_regex "with_foo"
85
+ should_match_regex "with_foo_or_bar_or_zeta", 'foo_or_bar_or_zeta'
86
+ end
87
+
88
+ module Macros
89
+ def should_match_regex string, *groups
90
+ context "matching #{string.inspect}" do
91
+ should("match") { assert_match @regex, string }
92
+
93
+ unless groups.blank?
94
+ context "should capture groups #{groups.inspect}" do
95
+ evaluate { @captures = @regex.match(string).captures }
96
+ should("match expected group values") do
97
+ assert_equal groups, @captures
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ def should_not_match_regex string
105
+ should "not match #{string.inspect}" do
106
+ assert_no_match @regex, string
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,3 @@
1
+ class Treat < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,12 @@
1
+ class CreateTreats < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :treats do |t|
4
+ t.integer :dog_id
5
+ t.timestamps
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :treats
11
+ end
12
+ end
metadata CHANGED
@@ -1,20 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ratnikov-shoulda
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6.2
4
+ version: 2.0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tammer Saleh
8
+ - Dmitry Ratnikov
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2008-12-10 00:00:00 -08:00
13
+ date: 2009-01-21 00:00:00 -08:00
13
14
  default_executable: convert_to_should_syntax
14
15
  dependencies: []
15
16
 
16
17
  description:
17
- email: tsaleh@thoughtbot.com
18
+ email: ratnikov@gmail.com
18
19
  executables:
19
20
  - convert_to_should_syntax
20
21
  extensions: []
@@ -23,139 +24,146 @@ extra_rdoc_files:
23
24
  - README.rdoc
24
25
  - CONTRIBUTION_GUIDELINES.rdoc
25
26
  files:
27
+ - README.rdoc
28
+ - Rakefile
26
29
  - CONTRIBUTION_GUIDELINES.rdoc
27
30
  - MIT-LICENSE
28
- - Rakefile
29
- - README.rdoc
30
31
  - bin/convert_to_should_syntax
31
32
  - lib/shoulda
32
- - lib/shoulda/action_mailer
33
- - lib/shoulda/action_mailer/assertions.rb
34
33
  - lib/shoulda/action_mailer.rb
35
- - lib/shoulda/active_record
36
- - lib/shoulda/active_record/assertions.rb
37
- - lib/shoulda/active_record/macros.rb
38
- - lib/shoulda/active_record.rb
39
- - lib/shoulda/assertions.rb
40
- - lib/shoulda/context.rb
34
+ - lib/shoulda/tasks.rb
41
35
  - lib/shoulda/controller
36
+ - lib/shoulda/controller/resource_options.rb
42
37
  - lib/shoulda/controller/formats
43
- - lib/shoulda/controller/formats/html.rb
44
38
  - lib/shoulda/controller/formats/xml.rb
39
+ - lib/shoulda/controller/formats/html.rb
45
40
  - lib/shoulda/controller/helpers.rb
46
41
  - lib/shoulda/controller/macros.rb
47
- - lib/shoulda/controller/resource_options.rb
48
42
  - lib/shoulda/controller.rb
43
+ - lib/shoulda/action_mailer
44
+ - lib/shoulda/action_mailer/assertions.rb
45
+ - lib/shoulda/assertions.rb
49
46
  - lib/shoulda/helpers.rb
50
- - lib/shoulda/macros.rb
47
+ - lib/shoulda/active_record.rb
48
+ - lib/shoulda/rails.rb
51
49
  - lib/shoulda/private_helpers.rb
50
+ - lib/shoulda/multiple_contexts.rb
52
51
  - lib/shoulda/proc_extensions.rb
53
- - lib/shoulda/rails.rb
54
52
  - lib/shoulda/tasks
55
- - lib/shoulda/tasks/list_tests.rake
56
53
  - lib/shoulda/tasks/yaml_to_shoulda.rake
57
- - lib/shoulda/tasks.rb
54
+ - lib/shoulda/tasks/list_tests.rake
55
+ - lib/shoulda/active_record
56
+ - lib/shoulda/active_record/assertions.rb
57
+ - lib/shoulda/active_record/macros.rb
58
+ - lib/shoulda/context.rb
59
+ - lib/shoulda/macros.rb
58
60
  - lib/shoulda.rb
59
61
  - rails/init.rb
62
+ - test/test_helper.rb
63
+ - test/README
60
64
  - test/fail_macros.rb
61
- - test/fixtures
62
- - test/fixtures/addresses.yml
63
- - test/fixtures/friendships.yml
64
- - test/fixtures/posts.yml
65
- - test/fixtures/products.yml
66
- - test/fixtures/taggings.yml
67
- - test/fixtures/tags.yml
68
- - test/fixtures/users.yml
69
- - test/functional
70
- - test/functional/posts_controller_test.rb
71
- - test/functional/users_controller_test.rb
72
- - test/other
73
- - test/other/context_test.rb
74
- - test/other/convert_to_should_syntax_test.rb
75
- - test/other/helpers_test.rb
76
- - test/other/private_helpers_test.rb
77
- - test/other/should_test.rb
78
65
  - test/rails_root
79
66
  - test/rails_root/app
80
- - test/rails_root/app/controllers
81
- - test/rails_root/app/controllers/application.rb
82
- - test/rails_root/app/controllers/posts_controller.rb
83
- - test/rails_root/app/controllers/users_controller.rb
84
67
  - test/rails_root/app/helpers
85
- - test/rails_root/app/helpers/application_helper.rb
86
- - test/rails_root/app/helpers/posts_helper.rb
87
68
  - test/rails_root/app/helpers/users_helper.rb
69
+ - test/rails_root/app/helpers/posts_helper.rb
70
+ - test/rails_root/app/helpers/application_helper.rb
88
71
  - test/rails_root/app/models
89
- - test/rails_root/app/models/address.rb
90
- - test/rails_root/app/models/pets/dog.rb
91
- - test/rails_root/app/models/flea.rb
92
72
  - test/rails_root/app/models/friendship.rb
93
73
  - test/rails_root/app/models/post.rb
94
- - test/rails_root/app/models/product.rb
74
+ - test/rails_root/app/models/pets
75
+ - test/rails_root/app/models/pets/dog.rb
76
+ - test/rails_root/app/models/address.rb
95
77
  - test/rails_root/app/models/tag.rb
78
+ - test/rails_root/app/models/flea.rb
96
79
  - test/rails_root/app/models/tagging.rb
80
+ - test/rails_root/app/models/product.rb
81
+ - test/rails_root/app/models/treat.rb
97
82
  - test/rails_root/app/models/user.rb
83
+ - test/rails_root/app/controllers
84
+ - test/rails_root/app/controllers/posts_controller.rb
85
+ - test/rails_root/app/controllers/application.rb
86
+ - test/rails_root/app/controllers/users_controller.rb
98
87
  - test/rails_root/app/views
99
- - test/rails_root/app/views/layouts
100
- - test/rails_root/app/views/layouts/posts.rhtml
101
- - test/rails_root/app/views/layouts/users.rhtml
102
- - test/rails_root/app/views/layouts/wide.html.erb
103
88
  - test/rails_root/app/views/posts
104
- - test/rails_root/app/views/posts/edit.rhtml
105
89
  - test/rails_root/app/views/posts/index.rhtml
106
- - test/rails_root/app/views/posts/new.rhtml
107
90
  - test/rails_root/app/views/posts/show.rhtml
91
+ - test/rails_root/app/views/posts/edit.rhtml
92
+ - test/rails_root/app/views/posts/new.rhtml
93
+ - test/rails_root/app/views/layouts
94
+ - test/rails_root/app/views/layouts/wide.html.erb
95
+ - test/rails_root/app/views/layouts/users.rhtml
96
+ - test/rails_root/app/views/layouts/posts.rhtml
108
97
  - test/rails_root/app/views/users
109
- - test/rails_root/app/views/users/edit.rhtml
110
98
  - test/rails_root/app/views/users/index.rhtml
111
- - test/rails_root/app/views/users/new.rhtml
112
99
  - test/rails_root/app/views/users/show.rhtml
113
- - test/rails_root/config
114
- - test/rails_root/config/boot.rb
115
- - test/rails_root/config/database.yml
116
- - test/rails_root/config/environment.rb
117
- - test/rails_root/config/environments
118
- - test/rails_root/config/environments/sqlite3.rb
119
- - test/rails_root/config/initializers
120
- - test/rails_root/config/initializers/new_rails_defaults.rb
121
- - test/rails_root/config/initializers/shoulda.rb
122
- - test/rails_root/config/routes.rb
100
+ - test/rails_root/app/views/users/edit.rhtml
101
+ - test/rails_root/app/views/users/new.rhtml
102
+ - test/rails_root/script
103
+ - test/rails_root/script/console
104
+ - test/rails_root/script/generate
105
+ - test/rails_root/log
106
+ - test/rails_root/log/sqlite3.log
123
107
  - test/rails_root/db
108
+ - test/rails_root/db/schema.rb
124
109
  - test/rails_root/db/migrate
125
110
  - test/rails_root/db/migrate/001_create_users.rb
126
- - test/rails_root/db/migrate/002_create_posts.rb
111
+ - test/rails_root/db/migrate/009_create_products.rb
127
112
  - test/rails_root/db/migrate/003_create_taggings.rb
128
- - test/rails_root/db/migrate/004_create_tags.rb
113
+ - test/rails_root/db/migrate/011_create_treats.rb
114
+ - test/rails_root/db/migrate/010_create_friendships.rb
115
+ - test/rails_root/db/migrate/008_create_dogs_fleas.rb
129
116
  - test/rails_root/db/migrate/005_create_dogs.rb
130
- - test/rails_root/db/migrate/006_create_addresses.rb
131
117
  - test/rails_root/db/migrate/007_create_fleas.rb
132
- - test/rails_root/db/migrate/008_create_dogs_fleas.rb
133
- - test/rails_root/db/migrate/009_create_products.rb
134
- - test/rails_root/db/migrate/010_create_friendships.rb
135
- - test/rails_root/db/schema.rb
136
- - test/rails_root/log
137
- - test/rails_root/log/sqlite3.log
118
+ - test/rails_root/db/migrate/006_create_addresses.rb
119
+ - test/rails_root/db/migrate/004_create_tags.rb
120
+ - test/rails_root/db/migrate/002_create_posts.rb
138
121
  - test/rails_root/public
139
- - test/rails_root/public/404.html
140
- - test/rails_root/public/422.html
141
122
  - test/rails_root/public/500.html
142
- - test/rails_root/script
143
- - test/rails_root/script/console
144
- - test/rails_root/script/generate
123
+ - test/rails_root/public/422.html
124
+ - test/rails_root/public/404.html
125
+ - test/rails_root/config
126
+ - test/rails_root/config/database.yml
127
+ - test/rails_root/config/boot.rb
128
+ - test/rails_root/config/environment.rb
129
+ - test/rails_root/config/environments
130
+ - test/rails_root/config/environments/sqlite3.rb
131
+ - test/rails_root/config/initializers
132
+ - test/rails_root/config/initializers/shoulda.rb
133
+ - test/rails_root/config/initializers/new_rails_defaults.rb
134
+ - test/rails_root/config/routes.rb
145
135
  - test/rails_root/vendor
146
136
  - test/rails_root/vendor/plugins
147
- - test/README
148
- - test/test_helper.rb
137
+ - test/other
138
+ - test/other/context_test.rb
139
+ - test/other/should_test.rb
140
+ - test/other/helpers_test.rb
141
+ - test/other/convert_to_should_syntax_test.rb
142
+ - test/other/multiple_contexts_test.rb
143
+ - test/other/private_helpers_test.rb
149
144
  - test/unit
150
- - test/unit/address_test.rb
151
- - test/unit/dog_test.rb
152
- - test/unit/flea_test.rb
153
145
  - test/unit/friendship_test.rb
146
+ - test/unit/flea_test.rb
147
+ - test/unit/user_test.rb
154
148
  - test/unit/post_test.rb
155
- - test/unit/product_test.rb
156
- - test/unit/tag_test.rb
157
149
  - test/unit/tagging_test.rb
158
- - test/unit/user_test.rb
150
+ - test/unit/tag_test.rb
151
+ - test/unit/product_test.rb
152
+ - test/unit/address_test.rb
153
+ - test/unit/dog_test.rb
154
+ - test/functional
155
+ - test/functional/posts_controller_test.rb
156
+ - test/functional/users_controller_test.rb
157
+ - test/fixtures
158
+ - test/fixtures/tags.yml
159
+ - test/fixtures/posts.yml
160
+ - test/fixtures/products.yml
161
+ - test/fixtures/friendships.yml
162
+ - test/fixtures/users.yml
163
+ - test/fixtures/taggings.yml
164
+ - test/fixtures/addresses.yml
165
+ - tasks/shoulda.rake
166
+ - init.rb
159
167
  has_rdoc: true
160
168
  homepage: http://thoughtbot.com/projects/shoulda
161
169
  post_install_message: