bubble-wrap 1.7.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +1 -1
  4. data/GETTING_STARTED.md +1 -1
  5. data/Gemfile.lock +10 -10
  6. data/README.md +266 -122
  7. data/Rakefile +1 -1
  8. data/bubble-wrap.gemspec +7 -6
  9. data/lib/bubble-wrap.rb +0 -1
  10. data/lib/bubble-wrap/all.rb +13 -1
  11. data/lib/bubble-wrap/location.rb +1 -1
  12. data/lib/bubble-wrap/motion.rb +10 -0
  13. data/lib/bubble-wrap/rss_parser.rb +0 -1
  14. data/lib/bubble-wrap/test.rb +1 -0
  15. data/lib/bubble-wrap/version.rb +1 -1
  16. data/motion/core/device/ios/camera.rb +12 -1
  17. data/motion/core/ios/device.rb +7 -1
  18. data/motion/core/json.rb +1 -1
  19. data/motion/core/osx/app.rb +11 -1
  20. data/motion/core/time.rb +27 -4
  21. data/motion/location/location.rb +6 -2
  22. data/motion/mail/mail.rb +4 -0
  23. data/motion/media/player.rb +2 -1
  24. data/motion/motion/motion.rb +421 -0
  25. data/motion/reactor/deferrable.rb +29 -3
  26. data/motion/reactor/eventable.rb +3 -1
  27. data/motion/reactor/thread_aware_deferrable.rb +37 -0
  28. data/motion/rss_parser.rb +11 -21
  29. data/motion/sms/sms.rb +4 -0
  30. data/motion/ui/ui_alert_view.rb +3 -1
  31. data/motion/ui/ui_control_wrapper.rb +27 -0
  32. data/motion/ui/ui_view_wrapper.rb +1 -7
  33. data/motion/util/constants.rb +1 -1
  34. data/samples/alert/Gemfile +1 -0
  35. data/samples/alert/Gemfile.lock +16 -0
  36. data/samples/alert/Rakefile +1 -1
  37. data/samples/camera/Gemfile +2 -1
  38. data/samples/camera/Gemfile.lock +16 -0
  39. data/samples/camera/Rakefile +1 -1
  40. data/samples/gesture/Gemfile +2 -1
  41. data/samples/gesture/Gemfile.lock +9 -3
  42. data/samples/gesture/Rakefile +1 -1
  43. data/samples/location/Gemfile +3 -1
  44. data/samples/location/Gemfile.lock +18 -0
  45. data/samples/location/Rakefile +4 -2
  46. data/samples/location/app/controllers/{image_list_controller.rb → places_list_controller.rb} +0 -0
  47. data/samples/media/Gemfile +4 -0
  48. data/samples/media/Gemfile.lock +16 -0
  49. data/samples/media/Rakefile +1 -1
  50. data/samples/osx/Gemfile +3 -1
  51. data/samples/osx/Gemfile.lock +5 -1
  52. data/spec/lib/bubble-wrap/requirement_spec.rb +2 -2
  53. data/spec/motion/core/app_spec.rb +23 -0
  54. data/spec/motion/core/device/ios/camera_spec.rb +1 -1
  55. data/spec/motion/core/device/ios/device_spec.rb +6 -0
  56. data/spec/motion/core/ios/app_spec.rb +9 -24
  57. data/spec/motion/core/json_spec.rb +30 -10
  58. data/spec/motion/core/osx/app_spec.rb +2 -1
  59. data/spec/motion/core/time_spec.rb +34 -1
  60. data/spec/motion/location/location_spec.rb +6 -0
  61. data/spec/motion/mail/mail_spec.rb +20 -16
  62. data/spec/motion/motion/core_motion_spec.rb +231 -0
  63. data/spec/motion/reactor/deferrable_spec.rb +81 -0
  64. data/spec/motion/reactor/eventable_spec.rb +11 -0
  65. data/spec/motion/reactor/thread_aware_deferrable_spec.rb +85 -0
  66. data/spec/motion/rss_parser_spec.rb +11 -21
  67. data/spec/motion/sms/sms_spec.rb +11 -6
  68. data/spec/motion/ui/ui_alert_view_spec.rb +23 -0
  69. data/spec/motion/ui/ui_control_wrapper_spec.rb +24 -0
  70. metadata +58 -38
  71. data/lib/bubble-wrap/http.rb +0 -7
@@ -0,0 +1,231 @@
1
+ describe BubbleWrap::Motion do
2
+
3
+ it 'should be able to instantiate all the things' do
4
+ mgr = CMMotionManager.alloc.init
5
+ mgr.should.be.kind_of(CMMotionManager)
6
+
7
+ accelerometer = BubbleWrap::Motion::Accelerometer.new(mgr)
8
+ accelerometer.should.be.kind_of(BubbleWrap::Motion::Accelerometer)
9
+
10
+ gyroscope = BubbleWrap::Motion::Gyroscope.new(mgr)
11
+ gyroscope.should.be.kind_of(BubbleWrap::Motion::Gyroscope)
12
+
13
+ magnetometer = BubbleWrap::Motion::Magnetometer.new(mgr)
14
+ magnetometer.should.be.kind_of(BubbleWrap::Motion::Magnetometer)
15
+
16
+ devicemotion = BubbleWrap::Motion::DeviceMotion.new(mgr)
17
+ devicemotion.should.be.kind_of(BubbleWrap::Motion::DeviceMotion)
18
+ end
19
+
20
+ describe 'BubbleWrap::Motion.manager' do
21
+ it 'should return a CMMotionManager' do
22
+ BubbleWrap::Motion.manager.should.be.kind_of(CMMotionManager)
23
+ end
24
+ it 'should be a shared instance' do
25
+ mgr1 = BubbleWrap::Motion.manager
26
+ mgr2 = BubbleWrap::Motion.manager
27
+ mgr1.should.equal? mgr2
28
+ end
29
+ end
30
+
31
+ describe 'BubbleWrap::Motion.accelerometer' do
32
+ it 'should be a BubbleWrap::Motion::Accelerometer' do
33
+ BubbleWrap::Motion.accelerometer.should.be.kind_of(BubbleWrap::Motion::Accelerometer)
34
+ end
35
+ it 'should be shared instanceAccelerometer' do
36
+ obj1 = BubbleWrap::Motion.accelerometer
37
+ obj2 = BubbleWrap::Motion.accelerometer
38
+ obj1.should.equal? obj2
39
+ end
40
+ it 'should not be available in the simulator' do
41
+ BubbleWrap::Motion.accelerometer.available?.should == false
42
+ end
43
+ it 'should not be active in the simulator' do
44
+ BubbleWrap::Motion.accelerometer.active?.should == false
45
+ end
46
+ it 'should not have data' do
47
+ BubbleWrap::Motion.accelerometer.data.should == nil
48
+ end
49
+ it 'should be able to start with a block' do
50
+ -> do
51
+ BubbleWrap::Motion.accelerometer.start {}
52
+ BubbleWrap::Motion.accelerometer.stop
53
+ end.should.not.raise
54
+ end
55
+ it 'should be able to start without a block' do
56
+ -> do
57
+ BubbleWrap::Motion.accelerometer.start
58
+ BubbleWrap::Motion.accelerometer.stop
59
+ end.should.not.raise
60
+ end
61
+ it 'should be able to repeat' do
62
+ -> do
63
+ BubbleWrap::Motion.accelerometer.repeat {}
64
+ BubbleWrap::Motion.accelerometer.stop
65
+ end.should.not.raise
66
+ end
67
+ it 'should be able to repeat via every' do
68
+ -> do
69
+ BubbleWrap::Motion.accelerometer.every(5) {}
70
+ BubbleWrap::Motion.accelerometer.stop
71
+ end.should.not.raise
72
+ end
73
+ it 'should be able to run once' do
74
+ -> do
75
+ BubbleWrap::Motion.accelerometer.once {}
76
+ BubbleWrap::Motion.accelerometer.stop
77
+ end.should.not.raise
78
+ end
79
+ end
80
+
81
+ describe 'BubbleWrap::Motion.gyroscope' do
82
+ it 'should be a BubbleWrap::Motion::Gyroscope' do
83
+ BubbleWrap::Motion.gyroscope.should.be.kind_of(BubbleWrap::Motion::Gyroscope)
84
+ end
85
+ it 'should be a shared instance' do
86
+ obj1 = BubbleWrap::Motion.gyroscope
87
+ obj2 = BubbleWrap::Motion.gyroscope
88
+ obj1.should.equal? obj2
89
+ end
90
+ it 'should not be available in the simulator' do
91
+ BubbleWrap::Motion.gyroscope.available?.should == false
92
+ end
93
+ it 'should not be active in the simulator' do
94
+ BubbleWrap::Motion.gyroscope.active?.should == false
95
+ end
96
+ it 'should not have data' do
97
+ BubbleWrap::Motion.gyroscope.data.should == nil
98
+ end
99
+ it 'should be able to start with a block' do
100
+ -> do
101
+ BubbleWrap::Motion.gyroscope.start {}
102
+ BubbleWrap::Motion.gyroscope.stop
103
+ end.should.not.raise
104
+ end
105
+ it 'should be able to start without a block' do
106
+ -> do
107
+ BubbleWrap::Motion.gyroscope.start
108
+ BubbleWrap::Motion.gyroscope.stop
109
+ end.should.not.raise
110
+ end
111
+ it 'should be able to repeat' do
112
+ -> do
113
+ BubbleWrap::Motion.gyroscope.repeat {}
114
+ BubbleWrap::Motion.gyroscope.stop
115
+ end.should.not.raise
116
+ end
117
+ it 'should be able to repeat via every' do
118
+ -> do
119
+ BubbleWrap::Motion.gyroscope.every(5) {}
120
+ BubbleWrap::Motion.gyroscope.stop
121
+ end.should.not.raise
122
+ end
123
+ it 'should be able to run once' do
124
+ -> do
125
+ BubbleWrap::Motion.gyroscope.once {}
126
+ BubbleWrap::Motion.gyroscope.stop
127
+ end.should.not.raise
128
+ end
129
+ end
130
+
131
+ describe 'BubbleWrap::Motion.magnetometer' do
132
+ it 'should be a BubbleWrap::Motion::Magnetometer' do
133
+ BubbleWrap::Motion.magnetometer.should.be.kind_of(BubbleWrap::Motion::Magnetometer)
134
+ end
135
+ it 'should be a shared instance' do
136
+ obj1 = BubbleWrap::Motion.magnetometer
137
+ obj2 = BubbleWrap::Motion.magnetometer
138
+ obj1.should.equal? obj2
139
+ end
140
+ it 'should not be available in the simulator' do
141
+ BubbleWrap::Motion.magnetometer.available?.should == false
142
+ end
143
+ it 'should not be active in the simulator' do
144
+ BubbleWrap::Motion.magnetometer.active?.should == false
145
+ end
146
+ it 'should not have data' do
147
+ BubbleWrap::Motion.magnetometer.data.should == nil
148
+ end
149
+ it 'should be able to start with a block' do
150
+ -> do
151
+ BubbleWrap::Motion.magnetometer.start {}
152
+ BubbleWrap::Motion.magnetometer.stop
153
+ end.should.not.raise
154
+ end
155
+ it 'should be able to start without a block' do
156
+ -> do
157
+ BubbleWrap::Motion.magnetometer.start
158
+ BubbleWrap::Motion.magnetometer.stop
159
+ end.should.not.raise
160
+ end
161
+ it 'should be able to repeat' do
162
+ -> do
163
+ BubbleWrap::Motion.magnetometer.repeat {}
164
+ BubbleWrap::Motion.magnetometer.stop
165
+ end.should.not.raise
166
+ end
167
+ it 'should be able to repeat via every' do
168
+ -> do
169
+ BubbleWrap::Motion.magnetometer.every(5) {}
170
+ BubbleWrap::Motion.magnetometer.stop
171
+ end.should.not.raise
172
+ end
173
+ it 'should be able to run once' do
174
+ -> do
175
+ BubbleWrap::Motion.magnetometer.once {}
176
+ BubbleWrap::Motion.magnetometer.stop
177
+ end.should.not.raise
178
+ end
179
+ end
180
+
181
+ describe 'BubbleWrap::Motion.device' do
182
+ it 'should be a BubbleWrap::Motion::DeviceMotion' do
183
+ BubbleWrap::Motion.device.should.be.kind_of(BubbleWrap::Motion::DeviceMotion)
184
+ end
185
+ it 'should be a shared instance' do
186
+ obj1 = BubbleWrap::Motion.device
187
+ obj2 = BubbleWrap::Motion.device
188
+ obj1.should.equal? obj2
189
+ end
190
+ it 'should not be available in the simulator' do
191
+ BubbleWrap::Motion.device.available?.should == false
192
+ end
193
+ it 'should not be active in the simulator' do
194
+ BubbleWrap::Motion.device.active?.should == false
195
+ end
196
+ it 'should not have data' do
197
+ BubbleWrap::Motion.device.data.should == nil
198
+ end
199
+ it 'should be able to start with a block' do
200
+ -> do
201
+ BubbleWrap::Motion.device.start {}
202
+ BubbleWrap::Motion.device.stop
203
+ end.should.not.raise
204
+ end
205
+ it 'should be able to start without a block' do
206
+ -> do
207
+ BubbleWrap::Motion.device.start
208
+ BubbleWrap::Motion.device.stop
209
+ end.should.not.raise
210
+ end
211
+ it 'should be able to repeat' do
212
+ -> do
213
+ BubbleWrap::Motion.device.repeat {}
214
+ BubbleWrap::Motion.device.stop
215
+ end.should.not.raise
216
+ end
217
+ it 'should be able to repeat via every' do
218
+ -> do
219
+ BubbleWrap::Motion.device.every(5) {}
220
+ BubbleWrap::Motion.device.stop
221
+ end.should.not.raise
222
+ end
223
+ it 'should be able to run once' do
224
+ -> do
225
+ BubbleWrap::Motion.device.once {}
226
+ BubbleWrap::Motion.device.stop
227
+ end.should.not.raise
228
+ end
229
+ end
230
+
231
+ end
@@ -0,0 +1,81 @@
1
+ describe BubbleWrap::Reactor::Deferrable do
2
+
3
+ before do
4
+ @subject = Class.new do
5
+ include BubbleWrap::Reactor::Deferrable
6
+ end
7
+ @object = @subject.new
8
+ end
9
+
10
+ describe '.callback' do
11
+
12
+ it "calls the callback block with arguments after .succeed" do
13
+ args = [1, 2]
14
+ @object.callback do |*passed_args|
15
+ passed_args.should.equal args
16
+ end
17
+ @object.succeed *args
18
+ end
19
+
20
+ it "calls the callback if even if the deferrable already suceeded" do
21
+ @object.succeed :succeeded
22
+ @object.callback do |*args|
23
+ args[0].should.equal :succeeded
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ describe '.errback' do
30
+ it "calls the errback block after the deferrable fails" do
31
+ args = [1, 2]
32
+ @object.errback do |*passed_args|
33
+ passed_args.should.equal args
34
+ end
35
+ @object.fail *args
36
+ end
37
+
38
+ it "calls the errback block even if the deferrable failed first" do
39
+ @object.fail :err
40
+ @object.errback do |err|
41
+ err.should.equal :err
42
+ end
43
+ end
44
+ end
45
+
46
+ describe '.delegate' do
47
+ it "passes the delegate to both .errback_delegate and .callback_delegate" do
48
+ @object.define_singleton_method(:callback_delegate) { |d| @callback_delegated = true }
49
+ @object.define_singleton_method(:errback_delegate) { |d| @errback_delegated = true }
50
+
51
+ @object.delegate(@subject.new)
52
+ @object.instance_variable_get("@callback_delegated").should.equal true
53
+ @object.instance_variable_get("@errback_delegated").should.equal true
54
+ end
55
+ end
56
+
57
+ describe '.errback_delegate' do
58
+ it "calls the delegate errback method when the deferrable fails" do
59
+ delegate = @subject.new
60
+ @object.errback_delegate delegate
61
+
62
+ delegate.errback do |*args|
63
+ args[0].should.equal :err
64
+ end
65
+ @object.fail :err
66
+ end
67
+ end
68
+
69
+ describe '.callback_delegate' do
70
+ it "calls the delegate callback when the deferrable suceeds" do
71
+ delegate = @subject.new
72
+ @object.callback_delegate delegate
73
+
74
+ delegate.callback do |*args|
75
+ args[0].should.equal :passed
76
+ end
77
+ @object.succeed :passed
78
+ end
79
+ end
80
+
81
+ end
@@ -48,6 +48,17 @@ describe BubbleWrap::Reactor::Eventable do
48
48
  events[:foo].member?(proof).should == false
49
49
  end
50
50
 
51
+ it 'unregisters all events' do
52
+ def bar; end
53
+ proof = method(:bar)
54
+ @subject.on(:foo, proof)
55
+ proof_2 = proc { }
56
+ @subject.on(:foo, &proof_2)
57
+ events = @subject.instance_variable_get(:@__events__)
58
+ @subject.off(:foo)
59
+ events[:foo].should == []
60
+ end
61
+
51
62
  it 'unregisters method events after kvo' do
52
63
  observing_object = Class.new do
53
64
  include BubbleWrap::KVO
@@ -0,0 +1,85 @@
1
+ shared :queue_caching_deferrable_method do
2
+ it "stores the current queue that is being used when a callback is added" do
3
+ @subject.send(@method, &@blk)
4
+ cache = @subject.instance_variable_get("@queue_cache")
5
+ cache.should.not.be.nil
6
+ cache[@blk.object_id].to_s.should.equal Dispatch::Queue.main.to_s
7
+ end
8
+
9
+ it "stores the queue, even if its not the main" do
10
+ @queue.async do
11
+ @subject.send(@method, &@blk)
12
+ Dispatch::Queue.main.async { resume }
13
+ end
14
+ wait do
15
+ cache = @subject.instance_variable_get("@queue_cache")
16
+ cache.should.not.be.nil
17
+ cache[@blk.object_id].to_s.should.equal @queue.to_s
18
+ end
19
+ end
20
+ end
21
+
22
+ shared :queue_block_execution do
23
+ it "calls the block on the right thread, with deferred argument once the deferrable is finished" do
24
+ @queue.async do
25
+ @subject.send(@block_method) do |*args|
26
+ Dispatch::Queue.current.to_s.should.equal @queue.to_s
27
+ args.should.equal [true]
28
+ Dispatch::Queue.main.async { resume }
29
+ end
30
+ end
31
+ @subject.send(@status_method, true)
32
+
33
+ wait {}
34
+ end
35
+
36
+ it "removes the queue from internal cache once the deferrable is finished" do
37
+ @subject.send(@block_method) do |*args|
38
+ Dispatch::Queue.main.async { resume }
39
+ end
40
+ @subject.send(@status_method, true)
41
+
42
+ wait do
43
+ @subject.instance_variable_get("@queue_cache").length.should.equal 0
44
+ end
45
+ end
46
+ end
47
+
48
+ describe BubbleWrap::Reactor::ThreadAwareDeferrable do
49
+
50
+ before do
51
+ @subject = BubbleWrap::Reactor::ThreadAwareDeferrable.new
52
+ @queue = Dispatch::Queue.new(:test_queue.to_s)
53
+ @blk = Proc.new {|*args| }
54
+ end
55
+
56
+ describe '.callback' do
57
+ before do
58
+ @method = :callback
59
+ end
60
+ behaves_like :queue_caching_deferrable_method
61
+ end
62
+
63
+ describe '.errback' do
64
+ before do
65
+ @method = :errback
66
+ end
67
+ behaves_like :queue_caching_deferrable_method
68
+ end
69
+
70
+ describe '.succeed' do
71
+ before do
72
+ @block_method = :callback
73
+ @status_method = :succeed
74
+ end
75
+ behaves_like :queue_block_execution
76
+ end
77
+
78
+ describe '.fail' do
79
+ before do
80
+ @block_method = :callback
81
+ @status_method = :succeed
82
+ end
83
+ behaves_like :queue_block_execution
84
+ end
85
+ end
@@ -1,4 +1,5 @@
1
1
  describe "RSSParser" do
2
+ extend WebStub::SpecHelpers
2
3
 
3
4
  before do
4
5
  @feed_url = 'https://raw.github.com/gist/2952427/9f1522cbe5d77a72c7c96c4fdb4b77bd58d7681e/atom.xml'
@@ -32,6 +33,11 @@ describe "RSSParser" do
32
33
  end
33
34
 
34
35
  it "parses url data" do
36
+ string = File.read(File.join(App.resources_path, 'atom.xml'))
37
+
38
+ stub_request(:get, @feed_url).
39
+ to_return(body: string, content_type: "application/xml")
40
+
35
41
  parser = BW::RSSParser.new(@feed_url)
36
42
  episodes = []
37
43
  parser.parse { |episode| episodes << episode }
@@ -40,28 +46,12 @@ describe "RSSParser" do
40
46
  end
41
47
 
42
48
  it "handles errors" do
43
- parser = BW::RSSParser.new("http://doesnotexist.com")
44
- parser.parse
45
- parser.state.should.equal :errors
46
- end
49
+ error_url = 'http://doesnotexist.com'
47
50
 
48
- module BW
49
- module HTTP
50
- class << self
51
- # To avoid interfering the http_spec's mocking, we only want to override HTTP.get if it's
52
- # for the RSSParser spec.
53
- alias_method :original_get, :get
54
- def get(url, options = {}, &block)
55
- if url == 'https://raw.github.com/gist/2952427/9f1522cbe5d77a72c7c96c4fdb4b77bd58d7681e/atom.xml'
56
- string = File.read(File.join(App.resources_path, 'atom.xml'))
57
- yield BW::HTTP::Response.new(body: string.to_data, status_code: 200)
58
- elsif url == 'http://doesnotexist.com'
59
- yield BW::HTTP::Response.new(status_code: nil)
60
- else
61
- original_get(url, options, &block)
62
- end
63
- end
64
- end
51
+ parser = BW::RSSParser.new(error_url)
52
+ parser.parse
53
+ wait 0.1 do
54
+ parser.state.should.equal :errors
65
55
  end
66
56
  end
67
57
  end