bubble-wrap 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/CHANGELOG.md +4 -0
- data/README.md +26 -15
- data/Rakefile +3 -2
- data/lib/bubble-wrap.rb +2 -2
- data/lib/bubble-wrap/app.rb +58 -33
- data/lib/bubble-wrap/device.rb +66 -0
- data/lib/bubble-wrap/device/screen.rb +69 -0
- data/lib/bubble-wrap/gestures.rb +15 -14
- data/lib/bubble-wrap/http.rb +25 -19
- data/lib/bubble-wrap/module.rb +24 -0
- data/lib/bubble-wrap/ns_notification_center.rb +8 -10
- data/lib/bubble-wrap/persistence.rb +27 -0
- data/lib/bubble-wrap/time.rb +8 -0
- data/lib/bubble-wrap/{ui_button.rb → ui_control.rb} +1 -1
- data/lib/bubble-wrap/version.rb +1 -1
- data/lib/pollute.rb +1 -1
- data/lib/tests/test_suite_delegate.rb +2 -0
- data/spec/app_spec.rb +83 -0
- data/spec/device/screen_spec.rb +153 -0
- data/spec/device_spec.rb +112 -0
- data/spec/gestures_spec.rb +51 -0
- data/spec/http_spec.rb +363 -0
- data/spec/json_spec.rb +0 -2
- data/spec/module_spec.rb +2 -0
- data/spec/ns_index_path_spec.rb +8 -6
- data/spec/ns_notification_center_spec.rb +14 -9
- data/spec/persistence_spec.rb +20 -0
- data/spec/time_spec.rb +41 -0
- data/spec/{ui_button_spec.rb → ui_control_spec.rb} +11 -1
- metadata +24 -6
- data/lib/bubble-wrap/kernel.rb +0 -105
@@ -0,0 +1,24 @@
|
|
1
|
+
module BubbleWrap
|
2
|
+
module_function
|
3
|
+
|
4
|
+
# @return [UIcolor]
|
5
|
+
def rgb_color(r,g,b)
|
6
|
+
rgba_color(r,g,b,1)
|
7
|
+
end
|
8
|
+
|
9
|
+
# @return [UIcolor]
|
10
|
+
def rgba_color(r,g,b,a)
|
11
|
+
UIColor.colorWithRed((r/255.0), green:(g/255.0), blue:(b/255.0), alpha:a)
|
12
|
+
end
|
13
|
+
|
14
|
+
def NSLocalizedString(key, value)
|
15
|
+
NSBundle.mainBundle.localizedStringForKey(key, value:value, table:nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
# I had issues with #p on the device, this is a temporary workaround
|
19
|
+
def p(arg)
|
20
|
+
NSLog arg.inspect
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
BW = BubbleWrap
|
@@ -1,23 +1,21 @@
|
|
1
1
|
class NSNotificationCenter
|
2
2
|
def observers
|
3
|
-
@observers ||=
|
3
|
+
@observers ||= []
|
4
4
|
end
|
5
5
|
|
6
|
-
def observe(
|
7
|
-
|
8
|
-
observers
|
9
|
-
|
6
|
+
def observe(name, object=nil, &proc)
|
7
|
+
observer = self.addObserverForName(name, object:object, queue:NSOperationQueue.mainQueue, usingBlock:proc)
|
8
|
+
observers << observer
|
9
|
+
observer
|
10
10
|
end
|
11
11
|
|
12
12
|
def unobserve(observer)
|
13
|
-
return unless observers
|
14
|
-
|
15
|
-
removeObserver(proc)
|
16
|
-
end
|
13
|
+
return unless observers.include?(observer)
|
14
|
+
removeObserver(observer)
|
17
15
|
observers.delete(observer)
|
18
16
|
end
|
19
17
|
|
20
18
|
def post(name, object=nil, info=nil)
|
21
|
-
self.postNotificationName(name, object: object, userInfo:info)
|
19
|
+
self.postNotificationName(name, object: object, userInfo: info)
|
22
20
|
end
|
23
21
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Persistence module built on top of NSUserDefaults
|
2
|
+
module BubbleWrap
|
3
|
+
module Persistence
|
4
|
+
module_function
|
5
|
+
|
6
|
+
def app_key
|
7
|
+
@app_key ||= BubbleWrap::App.identifier
|
8
|
+
end
|
9
|
+
|
10
|
+
def []=(key, value)
|
11
|
+
defaults = NSUserDefaults.standardUserDefaults
|
12
|
+
defaults.setObject(value, forKey: storage_key(key.to_s))
|
13
|
+
defaults.synchronize
|
14
|
+
end
|
15
|
+
|
16
|
+
def [](key)
|
17
|
+
defaults = NSUserDefaults.standardUserDefaults
|
18
|
+
defaults.objectForKey storage_key(key.to_s)
|
19
|
+
end
|
20
|
+
|
21
|
+
def storage_key(key)
|
22
|
+
app_key + '_' + key.to_s
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
::Persistence = BubbleWrap::Persistence
|
data/lib/bubble-wrap/version.rb
CHANGED
data/lib/pollute.rb
CHANGED
data/spec/app_spec.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
describe BubbleWrap::App do
|
2
|
+
describe '.documents_path' do
|
3
|
+
it 'should end in "/Documents"' do
|
4
|
+
BW::App.documents_path[-10..-1].should == '/Documents'
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.resources_path' do
|
9
|
+
it 'should end in "/MotionLibTestSuite.app"' do
|
10
|
+
BW::App.resources_path[-19..-1].should == '/testSuite_spec.app'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.notification_center' do
|
15
|
+
it 'should be a NSNotificationCenter' do
|
16
|
+
BW::App.notification_center.class.should == NSNotificationCenter
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '.user_cache' do
|
21
|
+
it 'should be a NSUserDefaults' do
|
22
|
+
BW::App.user_cache.class.should == NSUserDefaults
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.alert' do
|
27
|
+
before do
|
28
|
+
@alert = BW::App.alert('1.21 Gigawatts!', 'Great Scott!')
|
29
|
+
end
|
30
|
+
|
31
|
+
after do
|
32
|
+
@alert.removeFromSuperview
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns an alert' do
|
36
|
+
@alert.class.should == UIAlertView
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'is displaying the correct title' do
|
40
|
+
@alert.title.should == '1.21 Gigawatts!'
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'cancelButton' do
|
44
|
+
it 'is present' do
|
45
|
+
@alert.cancelButtonIndex.should == 0
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'has the correct title' do
|
49
|
+
@alert.buttonTitleAtIndex(@alert.cancelButtonIndex).should == 'Great Scott!'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '.states' do
|
55
|
+
it 'returns a hash' do
|
56
|
+
BW::App.states.class.should == Hash
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '.name' do
|
61
|
+
it 'returns the application name' do
|
62
|
+
BW::App.name.should == 'testSuite'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '.identifier' do
|
67
|
+
it 'returns the application identifier' do
|
68
|
+
BW::App.identifier.should == 'io.bubblewrap.testSuite'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '.frame' do
|
73
|
+
it 'returns a CGRect' do
|
74
|
+
BW::App.frame.class.should == CGRect
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '.delegate' do
|
79
|
+
it 'returns a TestSuiteDelegate' do
|
80
|
+
BW::App.delegate.class.should == TestSuiteDelegate
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
describe BubbleWrap::Device::Screen do
|
2
|
+
|
3
|
+
describe 'on retina enabled screen' do
|
4
|
+
before do
|
5
|
+
@screen = Object.new.tap do |o|
|
6
|
+
def o.respondsToSelector(selector)
|
7
|
+
return true if selector == 'displayLinkWithTarget:selector:'
|
8
|
+
UIDevice.mainDevice.respondsToSelector(selector)
|
9
|
+
end
|
10
|
+
def o.scale
|
11
|
+
2.0
|
12
|
+
end
|
13
|
+
def o.method_missing(*args)
|
14
|
+
UIDevice.mainDevice.send(*args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '.retina?' do
|
20
|
+
it 'returns true' do
|
21
|
+
BW::Device::Screen.retina?(@screen).should == true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'on non-retina enabled screen' do
|
27
|
+
before do
|
28
|
+
@screen = Object.new.tap do |o|
|
29
|
+
def o.respondsToSelector(selector)
|
30
|
+
return false if selector == 'displayLinkWithTarget:selector:'
|
31
|
+
UIDevice.mainDevice.respondsToSelector(selector)
|
32
|
+
end
|
33
|
+
def o.scale
|
34
|
+
1.0
|
35
|
+
end
|
36
|
+
def o.method_missing(*args)
|
37
|
+
UIDevice.mainDevice.send(*args)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '.retina?' do
|
43
|
+
it 'returns false' do
|
44
|
+
BW::Device::Screen.retina?(@screen).should == false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '.orientation' do
|
50
|
+
|
51
|
+
describe 'portrait' do
|
52
|
+
it 'returns :portrait' do
|
53
|
+
BW::Device::Screen.orientation(UIDeviceOrientationPortrait).should == :portrait
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'portrait upside down' do
|
58
|
+
it 'returns :portrait_upside_down' do
|
59
|
+
BW::Device::Screen.orientation(UIDeviceOrientationPortraitUpsideDown).should == :portrait_upside_down
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'landscape left' do
|
64
|
+
it 'returns :landscape_left' do
|
65
|
+
BW::Device::Screen.orientation(UIDeviceOrientationLandscapeLeft).should == :landscape_left
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe 'landscape right' do
|
70
|
+
it 'returns :landscape_right' do
|
71
|
+
BW::Device::Screen.orientation(UIDeviceOrientationLandscapeRight).should == :landscape_right
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe 'face up' do
|
76
|
+
it 'returns :face_up' do
|
77
|
+
BW::Device::Screen.orientation(UIDeviceOrientationFaceUp).should == :face_up
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'face down' do
|
82
|
+
it 'returns :face_down' do
|
83
|
+
BW::Device::Screen.orientation(UIDeviceOrientationFaceDown).should == :face_down
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'unknown' do
|
88
|
+
it 'returns :unknown' do
|
89
|
+
BW::Device::Screen.orientation(UIDeviceOrientationUnknown).should == :unknown
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'any other input' do
|
94
|
+
it 'returns :unknown' do
|
95
|
+
BW::Device::Screen.orientation('twiggy twiggy twiggy').should == :unknown
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '.width' do
|
101
|
+
it 'returns the current device screen width' do
|
102
|
+
BW::Device::Screen.width.should == 320.0 if BW::Device.iphone?
|
103
|
+
BW::Device::Screen.width.should == 768.0 if BW::Device.ipad?
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '.height' do
|
108
|
+
it 'returns the current device screen height' do
|
109
|
+
BW::Device::Screen.height.should == 480.0 if BW::Device.iphone?
|
110
|
+
BW::Device::Screen.height.should == 1024.0 if BW::Device.ipad?
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '.widthForOrientation' do
|
115
|
+
describe ':landscape_left' do
|
116
|
+
it 'returns the current device screen height' do
|
117
|
+
BW::Device::Screen.widthForOrientation(:landscape_left).should == BW::Device::Screen.height
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe ':landscape_right' do
|
122
|
+
it 'returns the current device screen height' do
|
123
|
+
BW::Device::Screen.widthForOrientation(:landscape_right).should == BW::Device::Screen.height
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe 'default' do
|
128
|
+
it 'returns the current device screen width' do
|
129
|
+
BW::Device::Screen.widthForOrientation.should == BW::Device::Screen.width
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '.heightForOrientation' do
|
135
|
+
describe ':landscape_left' do
|
136
|
+
it 'returns the current device screen width' do
|
137
|
+
BW::Device::Screen.heightForOrientation(:landscape_left).should == BW::Device::Screen.width
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe ':landscape_right' do
|
142
|
+
it 'returns the current device screen width' do
|
143
|
+
BW::Device::Screen.heightForOrientation(:landscape_right).should == BW::Device::Screen.width
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe 'default' do
|
148
|
+
it 'returns the current device screen height' do
|
149
|
+
BW::Device::Screen.heightForOrientation.should == BW::Device::Screen.height
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
data/spec/device_spec.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
describe BubbleWrap::Device do
|
2
|
+
|
3
|
+
describe 'on iPhone' do
|
4
|
+
before do
|
5
|
+
@idiom = UIUserInterfaceIdiomPhone
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.iphone?' do
|
9
|
+
it 'returns true' do
|
10
|
+
BW::Device.iphone?(@idiom).should == true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.ipad?' do
|
15
|
+
it 'returns false' do
|
16
|
+
BW::Device.ipad?(@idiom).should == false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'on iPad' do
|
22
|
+
before do
|
23
|
+
@idiom = UIUserInterfaceIdiomPad
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.iphone?' do
|
27
|
+
it 'returns false' do
|
28
|
+
BW::Device.iphone?(@idiom).should == false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '.ipad?' do
|
33
|
+
it 'returns true' do
|
34
|
+
BW::Device.ipad?(@idiom).should == true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'on device with only front facing camera' do
|
40
|
+
before do
|
41
|
+
@picker = Object.new.tap do |o|
|
42
|
+
def o.isCameraDeviceAvailable(c)
|
43
|
+
c == UIImagePickerControllerCameraDeviceFront
|
44
|
+
end
|
45
|
+
def o.method_missing(*args)
|
46
|
+
UIImagePickerController.send(*args)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '.front_camera?' do
|
52
|
+
it 'returns true' do
|
53
|
+
BW::Device.front_camera?(@picker).should == true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '.rear_camera?' do
|
58
|
+
it 'returns false' do
|
59
|
+
BW::Device.rear_camera?(@picker).should == false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'on device with only rear facing camera' do
|
65
|
+
before do
|
66
|
+
@picker = Object.new.tap do |o|
|
67
|
+
def o.isCameraDeviceAvailable(c)
|
68
|
+
c == UIImagePickerControllerCameraDeviceRear
|
69
|
+
end
|
70
|
+
def o.method_missing(*args)
|
71
|
+
UIImagePickerController.send(*args)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '.front_camera?' do
|
77
|
+
it 'returns false' do
|
78
|
+
BW::Device.front_camera?(@picker).should == false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '.rear_camera?' do
|
83
|
+
it 'returns true' do
|
84
|
+
BW::Device.rear_camera?(@picker).should == true
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '.simulator?' do
|
90
|
+
it 'returns true' do
|
91
|
+
BW::Device.simulator?.should == true
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '.screen' do
|
96
|
+
it 'return BubbleWrap::Screen' do
|
97
|
+
BW::Device.screen.should == BW::Device::Screen
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '.retina?' do
|
102
|
+
it 'delegates to BubbleWrap::Screen.retina?' do
|
103
|
+
BW::Device.retina?.should == BW::Device::Screen.retina?
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '.orientation' do
|
108
|
+
it 'delegates to BubbleWrap::Screen.orientation' do
|
109
|
+
BW::Device.orientation.should == BW::Device::Screen.orientation
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|