gnip 0.4.2

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.
Files changed (89) hide show
  1. data/README +144 -0
  2. data/Rakefile +53 -0
  3. data/TODO +72 -0
  4. data/bin/gnip +651 -0
  5. data/doc/api.html +1201 -0
  6. data/gemspec.rb +47 -0
  7. data/gnip-0.4.2.gem +0 -0
  8. data/lib/gnip.rb +71 -0
  9. data/lib/gnip/activity.rb +663 -0
  10. data/lib/gnip/api.rb +191 -0
  11. data/lib/gnip/arguments.rb +21 -0
  12. data/lib/gnip/blankslate.rb +5 -0
  13. data/lib/gnip/config.rb +144 -0
  14. data/lib/gnip/filter.rb +304 -0
  15. data/lib/gnip/list.rb +126 -0
  16. data/lib/gnip/options.rb +96 -0
  17. data/lib/gnip/orderedhash.rb +199 -0
  18. data/lib/gnip/publisher.rb +309 -0
  19. data/lib/gnip/resource.rb +301 -0
  20. data/lib/gnip/template.rb +44 -0
  21. data/lib/gnip/util.rb +120 -0
  22. data/sample/data/activity.yml +21 -0
  23. data/test/auth.rb +60 -0
  24. data/test/config.yml +2 -0
  25. data/test/data/activity.xml +14 -0
  26. data/test/data/activity_only_required.xml +4 -0
  27. data/test/data/activity_with_payload.xml +22 -0
  28. data/test/data/activity_with_place.xml +18 -0
  29. data/test/data/activity_with_place_wo_bounds.xml +36 -0
  30. data/test/data/activity_with_unbounded_media_urls.xml +44 -0
  31. data/test/data/activity_without_bounds.xml +24 -0
  32. data/test/helper.rb +115 -0
  33. data/test/helper.rb.bak +28 -0
  34. data/test/integration/auth.rb +12 -0
  35. data/test/integration/publisher.rb +86 -0
  36. data/test/lib/shoulda.rb +9 -0
  37. data/test/lib/shoulda/action_controller.rb +28 -0
  38. data/test/lib/shoulda/action_controller/helpers.rb +47 -0
  39. data/test/lib/shoulda/action_controller/macros.rb +277 -0
  40. data/test/lib/shoulda/action_controller/matchers.rb +37 -0
  41. data/test/lib/shoulda/action_controller/matchers/assign_to_matcher.rb +109 -0
  42. data/test/lib/shoulda/action_controller/matchers/filter_param_matcher.rb +57 -0
  43. data/test/lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb +81 -0
  44. data/test/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb +70 -0
  45. data/test/lib/shoulda/action_controller/matchers/respond_with_matcher.rb +77 -0
  46. data/test/lib/shoulda/action_controller/matchers/route_matcher.rb +93 -0
  47. data/test/lib/shoulda/action_controller/matchers/set_session_matcher.rb +83 -0
  48. data/test/lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb +85 -0
  49. data/test/lib/shoulda/action_mailer.rb +10 -0
  50. data/test/lib/shoulda/action_mailer/assertions.rb +38 -0
  51. data/test/lib/shoulda/action_view.rb +10 -0
  52. data/test/lib/shoulda/action_view/macros.rb +56 -0
  53. data/test/lib/shoulda/active_record.rb +16 -0
  54. data/test/lib/shoulda/active_record/assertions.rb +69 -0
  55. data/test/lib/shoulda/active_record/helpers.rb +40 -0
  56. data/test/lib/shoulda/active_record/macros.rb +586 -0
  57. data/test/lib/shoulda/active_record/matchers.rb +42 -0
  58. data/test/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +83 -0
  59. data/test/lib/shoulda/active_record/matchers/allow_value_matcher.rb +102 -0
  60. data/test/lib/shoulda/active_record/matchers/association_matcher.rb +226 -0
  61. data/test/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb +87 -0
  62. data/test/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb +141 -0
  63. data/test/lib/shoulda/active_record/matchers/have_db_column_matcher.rb +169 -0
  64. data/test/lib/shoulda/active_record/matchers/have_index_matcher.rb +105 -0
  65. data/test/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb +125 -0
  66. data/test/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb +59 -0
  67. data/test/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb +41 -0
  68. data/test/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb +39 -0
  69. data/test/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb +60 -0
  70. data/test/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb +148 -0
  71. data/test/lib/shoulda/active_record/matchers/validation_matcher.rb +56 -0
  72. data/test/lib/shoulda/assertions.rb +59 -0
  73. data/test/lib/shoulda/autoload_macros.rb +46 -0
  74. data/test/lib/shoulda/context.rb +304 -0
  75. data/test/lib/shoulda/helpers.rb +8 -0
  76. data/test/lib/shoulda/macros.rb +73 -0
  77. data/test/lib/shoulda/private_helpers.rb +20 -0
  78. data/test/lib/shoulda/proc_extensions.rb +14 -0
  79. data/test/lib/shoulda/rails.rb +13 -0
  80. data/test/lib/shoulda/rspec.rb +9 -0
  81. data/test/lib/shoulda/tasks.rb +3 -0
  82. data/test/lib/shoulda/tasks/list_tests.rake +29 -0
  83. data/test/lib/shoulda/tasks/yaml_to_shoulda.rake +28 -0
  84. data/test/lib/shoulda/test_unit.rb +19 -0
  85. data/test/lib/xmlsimple.rb +1021 -0
  86. data/test/loader.rb +25 -0
  87. data/test/unit/activity.rb +26 -0
  88. data/test/unit/util.rb +39 -0
  89. metadata +198 -0
@@ -0,0 +1,56 @@
1
+ module Shoulda # :nodoc:
2
+ module ActiveRecord # :nodoc:
3
+ module Matchers
4
+
5
+ class ValidationMatcher # :nodoc:
6
+
7
+ attr_reader :failure_message
8
+
9
+ def initialize(attribute)
10
+ @attribute = attribute
11
+ end
12
+
13
+ def negative_failure_message
14
+ @negative_failure_message || @failure_message
15
+ end
16
+
17
+ def matches?(subject)
18
+ @subject = subject
19
+ false
20
+ end
21
+
22
+ private
23
+
24
+ def allows_value_of(value, message = nil)
25
+ allow = AllowValueMatcher.
26
+ new(value).
27
+ for(@attribute).
28
+ with_message(message)
29
+ if allow.matches?(@subject)
30
+ @negative_failure_message = allow.failure_message
31
+ true
32
+ else
33
+ @failure_message = allow.negative_failure_message
34
+ false
35
+ end
36
+ end
37
+
38
+ def disallows_value_of(value, message = nil)
39
+ disallow = AllowValueMatcher.
40
+ new(value).
41
+ for(@attribute).
42
+ with_message(message)
43
+ if disallow.matches?(@subject)
44
+ @failure_message = disallow.negative_failure_message
45
+ false
46
+ else
47
+ @negative_failure_message = disallow.failure_message
48
+ true
49
+ end
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
+ end
56
+
@@ -0,0 +1,59 @@
1
+ module Shoulda # :nodoc:
2
+ module Assertions
3
+ # Asserts that two arrays contain the same elements, the same number of times. Essentially ==, but unordered.
4
+ #
5
+ # assert_same_elements([:a, :b, :c], [:c, :a, :b]) => passes
6
+ def assert_same_elements(a1, a2, msg = nil)
7
+ [:select, :inject, :size].each do |m|
8
+ [a1, a2].each {|a| assert_respond_to(a, m, "Are you sure that #{a.inspect} is an array? It doesn't respond to #{m}.") }
9
+ end
10
+
11
+ assert a1h = a1.inject({}) { |h,e| h[e] = a1.select { |i| i == e }.size; h }
12
+ assert a2h = a2.inject({}) { |h,e| h[e] = a2.select { |i| i == e }.size; h }
13
+
14
+ assert_equal(a1h, a2h, msg)
15
+ end
16
+
17
+ # Asserts that the given collection contains item x. If x is a regular expression, ensure that
18
+ # at least one element from the collection matches x. +extra_msg+ is appended to the error message if the assertion fails.
19
+ #
20
+ # assert_contains(['a', '1'], /\d/) => passes
21
+ # assert_contains(['a', '1'], 'a') => passes
22
+ # assert_contains(['a', '1'], /not there/) => fails
23
+ def assert_contains(collection, x, extra_msg = "")
24
+ collection = [collection] unless collection.is_a?(Array)
25
+ msg = "#{x.inspect} not found in #{collection.to_a.inspect} #{extra_msg}"
26
+ case x
27
+ when Regexp
28
+ assert(collection.detect { |e| e =~ x }, msg)
29
+ else
30
+ assert(collection.include?(x), msg)
31
+ end
32
+ end
33
+
34
+ # Asserts that the given collection does not contain item x. If x is a regular expression, ensure that
35
+ # none of the elements from the collection match x.
36
+ def assert_does_not_contain(collection, x, extra_msg = "")
37
+ collection = [collection] unless collection.is_a?(Array)
38
+ msg = "#{x.inspect} found in #{collection.to_a.inspect} " + extra_msg
39
+ case x
40
+ when Regexp
41
+ assert(!collection.detect { |e| e =~ x }, msg)
42
+ else
43
+ assert(!collection.include?(x), msg)
44
+ end
45
+ end
46
+
47
+ # Asserts that the given matcher returns true when +target+ is passed to #matches?
48
+ def assert_accepts(matcher, target)
49
+ success = matcher.matches?(target)
50
+ assert_block(matcher.failure_message) { success }
51
+ end
52
+
53
+ # Asserts that the given matcher returns false when +target+ is passed to #matches?
54
+ def assert_rejects(matcher, target)
55
+ success = !matcher.matches?(target)
56
+ assert_block(matcher.negative_failure_message) { success }
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,46 @@
1
+ module Shoulda # :nodoc:
2
+ # Call autoload_macros when you want to load test macros automatically in a non-Rails
3
+ # project (it's done automatically for Rails projects).
4
+ # You don't need to specify ROOT/test/shoulda_macros explicitly. Your custom macros
5
+ # are loaded automatically when you call autoload_macros.
6
+ #
7
+ # The first argument is the path to you application's root directory.
8
+ # All following arguments are directories relative to your root, which contain
9
+ # shoulda_macros subdirectories. These directories support the same kinds of globs as the
10
+ # Dir class.
11
+ #
12
+ # Basic usage (from a test_helper):
13
+ # Shoulda.autoload_macros(File.dirname(__FILE__) + '/..')
14
+ # will load everything in
15
+ # - your_app/test/shoulda_macros
16
+ #
17
+ # To load vendored macros as well:
18
+ # Shoulda.autoload_macros(APP_ROOT, 'vendor/*')
19
+ # will load everything in
20
+ # - APP_ROOT/vendor/*/shoulda_macros
21
+ # - APP_ROOT/test/shoulda_macros
22
+ #
23
+ # To load macros in an app with a vendor directory laid out like Rails':
24
+ # Shoulda.autoload_macros(APP_ROOT, 'vendor/{plugins,gems}/*')
25
+ # or
26
+ # Shoulda.autoload_macros(APP_ROOT, 'vendor/plugins/*', 'vendor/gems/*')
27
+ # will load everything in
28
+ # - APP_ROOT/vendor/plugins/*/shoulda_macros
29
+ # - APP_ROOT/vendor/gems/*/shoulda_macros
30
+ # - APP_ROOT/test/shoulda_macros
31
+ #
32
+ # If you prefer to stick testing dependencies away from your production dependencies:
33
+ # Shoulda.autoload_macros(APP_ROOT, 'vendor/*', 'test/vendor/*')
34
+ # will load everything in
35
+ # - APP_ROOT/vendor/*/shoulda_macros
36
+ # - APP_ROOT/test/vendor/*/shoulda_macros
37
+ # - APP_ROOT/test/shoulda_macros
38
+ def self.autoload_macros(root, *dirs)
39
+ dirs << File.join('test')
40
+ complete_dirs = dirs.map{|d| File.join(root, d, 'shoulda_macros')}
41
+ all_files = complete_dirs.inject([]){ |files, dir| files + Dir[File.join(dir, '*.rb')] }
42
+ all_files.each do |file|
43
+ require file
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,304 @@
1
+ module Shoulda
2
+ class << self
3
+ attr_writer :contexts
4
+ def contexts # :nodoc:
5
+ @contexts ||= []
6
+ end
7
+
8
+ def current_context # :nodoc:
9
+ self.contexts.last
10
+ end
11
+
12
+ def add_context(context) # :nodoc:
13
+ self.contexts.push(context)
14
+ end
15
+
16
+ def remove_context # :nodoc:
17
+ self.contexts.pop
18
+ end
19
+ end
20
+
21
+ module ClassMethods
22
+ # == Should statements
23
+ #
24
+ # Should statements are just syntactic sugar over normal Test::Unit test methods. A should block
25
+ # contains all the normal code and assertions you're used to seeing, with the added benefit that
26
+ # they can be wrapped inside context blocks (see below).
27
+ #
28
+ # === Example:
29
+ #
30
+ # class UserTest < Test::Unit::TestCase
31
+ #
32
+ # def setup
33
+ # @user = User.new("John", "Doe")
34
+ # end
35
+ #
36
+ # should "return its full name"
37
+ # assert_equal 'John Doe', @user.full_name
38
+ # end
39
+ #
40
+ # end
41
+ #
42
+ # ...will produce the following test:
43
+ # * <tt>"test: User should return its full name. "</tt>
44
+ #
45
+ # Note: The part before <tt>should</tt> in the test name is gleamed from the name of the Test::Unit class.
46
+ #
47
+ # Should statements can also take a Proc as a <tt>:before </tt>option. This proc runs after any
48
+ # parent context's setups but before the current context's setup.
49
+ #
50
+ # === Example:
51
+ #
52
+ # context "Some context" do
53
+ # setup { puts("I run after the :before proc") }
54
+ #
55
+ # should "run a :before proc", :before => lambda { puts("I run before the setup") } do
56
+ # assert true
57
+ # end
58
+ # end
59
+
60
+ def should(name, options = {}, &blk)
61
+ if Shoulda.current_context
62
+ block_given? ? Shoulda.current_context.should(name, options, &blk) : Should.current_context.should_eventually(name)
63
+ else
64
+ context_name = self.name.gsub(/Test/, "")
65
+ context = Shoulda::Context.new(context_name, self) do
66
+ block_given? ? should(name, options, &blk) : should_eventually(name)
67
+ end
68
+ context.build
69
+ end
70
+ end
71
+
72
+ # == Before statements
73
+ #
74
+ # Before statements are should statements that run before the current
75
+ # context's setup. These are especially useful when setting expectations.
76
+ #
77
+ # === Example:
78
+ #
79
+ # class UserControllerTest < Test::Unit::TestCase
80
+ # context "the index action" do
81
+ # setup do
82
+ # @users = [Factory(:user)]
83
+ # User.stubs(:find).returns(@users)
84
+ # end
85
+ #
86
+ # context "on GET" do
87
+ # setup { get :index }
88
+ #
89
+ # should_respond_with :success
90
+ #
91
+ # # runs before "get :index"
92
+ # before_should "find all users" do
93
+ # User.expects(:find).with(:all).returns(@users)
94
+ # end
95
+ # end
96
+ # end
97
+ # end
98
+ def before_should(name, &blk)
99
+ should(name, :before => blk) { assert true }
100
+ end
101
+
102
+ # Just like should, but never runs, and instead prints an 'X' in the Test::Unit output.
103
+ def should_eventually(name, options = {}, &blk)
104
+ context_name = self.name.gsub(/Test/, "")
105
+ context = Shoulda::Context.new(context_name, self) do
106
+ should_eventually(name, &blk)
107
+ end
108
+ context.build
109
+ end
110
+
111
+ # == Contexts
112
+ #
113
+ # A context block groups should statements under a common set of setup/teardown methods.
114
+ # Context blocks can be arbitrarily nested, and can do wonders for improving the maintainability
115
+ # and readability of your test code.
116
+ #
117
+ # A context block can contain setup, should, should_eventually, and teardown blocks.
118
+ #
119
+ # class UserTest < Test::Unit::TestCase
120
+ # context "A User instance" do
121
+ # setup do
122
+ # @user = User.find(:first)
123
+ # end
124
+ #
125
+ # should "return its full name"
126
+ # assert_equal 'John Doe', @user.full_name
127
+ # end
128
+ # end
129
+ # end
130
+ #
131
+ # This code will produce the method <tt>"test: A User instance should return its full name. "</tt>.
132
+ #
133
+ # Contexts may be nested. Nested contexts run their setup blocks from out to in before each
134
+ # should statement. They then run their teardown blocks from in to out after each should statement.
135
+ #
136
+ # class UserTest < Test::Unit::TestCase
137
+ # context "A User instance" do
138
+ # setup do
139
+ # @user = User.find(:first)
140
+ # end
141
+ #
142
+ # should "return its full name"
143
+ # assert_equal 'John Doe', @user.full_name
144
+ # end
145
+ #
146
+ # context "with a profile" do
147
+ # setup do
148
+ # @user.profile = Profile.find(:first)
149
+ # end
150
+ #
151
+ # should "return true when sent :has_profile?"
152
+ # assert @user.has_profile?
153
+ # end
154
+ # end
155
+ # end
156
+ # end
157
+ #
158
+ # This code will produce the following methods
159
+ # * <tt>"test: A User instance should return its full name. "</tt>
160
+ # * <tt>"test: A User instance with a profile should return true when sent :has_profile?. "</tt>
161
+ #
162
+ # <b>Just like should statements, a context block can exist next to normal <tt>def test_the_old_way; end</tt>
163
+ # tests</b>. This means you do not have to fully commit to the context/should syntax in a test file.
164
+
165
+ def context(name, &blk)
166
+ if Shoulda.current_context
167
+ Shoulda.current_context.context(name, &blk)
168
+ else
169
+ context = Shoulda::Context.new(name, self, &blk)
170
+ context.build
171
+ end
172
+ end
173
+ end
174
+
175
+ class Context # :nodoc:
176
+
177
+ attr_accessor :name # my name
178
+ attr_accessor :parent # may be another context, or the original test::unit class.
179
+ attr_accessor :subcontexts # array of contexts nested under myself
180
+ attr_accessor :setup_blocks # blocks given via setup methods
181
+ attr_accessor :teardown_blocks # blocks given via teardown methods
182
+ attr_accessor :shoulds # array of hashes representing the should statements
183
+ attr_accessor :should_eventuallys # array of hashes representing the should eventually statements
184
+
185
+ def initialize(name, parent, &blk)
186
+ Shoulda.add_context(self)
187
+ self.name = name
188
+ self.parent = parent
189
+ self.setup_blocks = []
190
+ self.teardown_blocks = []
191
+ self.shoulds = []
192
+ self.should_eventuallys = []
193
+ self.subcontexts = []
194
+
195
+ merge_block(&blk)
196
+ Shoulda.remove_context
197
+ end
198
+
199
+ def merge_block(&blk)
200
+ blk.bind(self).call
201
+ end
202
+
203
+ def context(name, &blk)
204
+ self.subcontexts << Context.new(name, self, &blk)
205
+ end
206
+
207
+ def setup(&blk)
208
+ self.setup_blocks << blk
209
+ end
210
+
211
+ def teardown(&blk)
212
+ self.teardown_blocks << blk
213
+ end
214
+
215
+ def should(name, options = {}, &blk)
216
+ if block_given?
217
+ self.shoulds << { :name => name, :before => options[:before], :block => blk }
218
+ else
219
+ self.should_eventuallys << { :name => name }
220
+ end
221
+ end
222
+
223
+ def should_eventually(name, &blk)
224
+ self.should_eventuallys << { :name => name, :block => blk }
225
+ end
226
+
227
+ def full_name
228
+ parent_name = parent.full_name if am_subcontext?
229
+ return [parent_name, name].join(" ").strip
230
+ end
231
+
232
+ def am_subcontext?
233
+ parent.is_a?(self.class) # my parent is the same class as myself.
234
+ end
235
+
236
+ def test_unit_class
237
+ am_subcontext? ? parent.test_unit_class : parent
238
+ end
239
+
240
+ def create_test_from_should_hash(should)
241
+ test_name = ["test:", full_name, "should", "#{should[:name]}. "].flatten.join(' ').to_sym
242
+
243
+ if test_unit_class.instance_methods.include?(test_name.to_s)
244
+ warn " * WARNING: '#{test_name}' is already defined"
245
+ end
246
+
247
+ context = self
248
+ test_unit_class.send(:define_method, test_name) do
249
+ begin
250
+ context.run_parent_setup_blocks(self)
251
+ should[:before].bind(self).call if should[:before]
252
+ context.run_current_setup_blocks(self)
253
+ should[:block].bind(self).call
254
+ ensure
255
+ context.run_all_teardown_blocks(self)
256
+ end
257
+ end
258
+ end
259
+
260
+ def run_all_setup_blocks(binding)
261
+ run_parent_setup_blocks(binding)
262
+ run_current_setup_blocks(binding)
263
+ end
264
+
265
+ def run_parent_setup_blocks(binding)
266
+ self.parent.run_all_setup_blocks(binding) if am_subcontext?
267
+ end
268
+
269
+ def run_current_setup_blocks(binding)
270
+ setup_blocks.each do |setup_block|
271
+ setup_block.bind(binding).call
272
+ end
273
+ end
274
+
275
+ def run_all_teardown_blocks(binding)
276
+ teardown_blocks.reverse.each do |teardown_block|
277
+ teardown_block.bind(binding).call
278
+ end
279
+ self.parent.run_all_teardown_blocks(binding) if am_subcontext?
280
+ end
281
+
282
+ def print_should_eventuallys
283
+ should_eventuallys.each do |should|
284
+ test_name = [full_name, "should", "#{should[:name]}. "].flatten.join(' ')
285
+ puts " * DEFERRED: " + test_name
286
+ end
287
+ end
288
+
289
+ def build
290
+ shoulds.each do |should|
291
+ create_test_from_should_hash(should)
292
+ end
293
+
294
+ subcontexts.each { |context| context.build }
295
+
296
+ print_should_eventuallys
297
+ end
298
+
299
+ def method_missing(method, *args, &blk)
300
+ test_unit_class.send(method, *args, &blk)
301
+ end
302
+
303
+ end
304
+ end