rspec_prank 0.1.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.
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +43 -0
- data/VERSION.yml +4 -0
- data/lib/rspec_prank.rb +124 -0
- data/spec/pranked_spec.rb +11 -0
- data/spec/spec_helper.rb +9 -0
- metadata +72 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Daniel Cadenas
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rspec_prank"
|
8
|
+
gem.summary = %Q{RSpec + Apple Motion Sensor = Fun}
|
9
|
+
gem.email = "dcadenas@gmail.com"
|
10
|
+
gem.homepage = "http://github.com/dcadenas/rspec_prank"
|
11
|
+
gem.authors = ["Daniel Cadenas"]
|
12
|
+
gem.files = FileList["[A-Z]*", "{bin,generators,lib,spec}/**/*"]
|
13
|
+
gem.add_dependency 'RubyInline'
|
14
|
+
|
15
|
+
#gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/rdoctask'
|
22
|
+
Rake::RDocTask.new do |rdoc|
|
23
|
+
rdoc.rdoc_dir = 'rdoc'
|
24
|
+
rdoc.title = 'rspec_prank'
|
25
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
26
|
+
rdoc.rdoc_files.include('README*')
|
27
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
28
|
+
end
|
29
|
+
|
30
|
+
require 'spec/rake/spectask'
|
31
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
32
|
+
spec.libs << 'lib' << 'spec'
|
33
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
34
|
+
end
|
35
|
+
|
36
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
37
|
+
spec.libs << 'lib' << 'spec'
|
38
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
39
|
+
spec.rcov = true
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
task :default => :spec
|
data/VERSION.yml
ADDED
data/lib/rspec_prank.rb
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require "inline"
|
3
|
+
require "spec/runner/formatter/progress_bar_formatter"
|
4
|
+
|
5
|
+
module RspecPrank
|
6
|
+
#Motion sensor code from FaziBear at http://fazibear.blogspot.com/2008/12/process-mac-sudden-motion-sensor-with.html
|
7
|
+
class SMS
|
8
|
+
class << self
|
9
|
+
inline do |builder|
|
10
|
+
builder.add_compile_flags '-x objective-c', '-framework IOKit'
|
11
|
+
builder.include "<IOKit/IOKitLib.h>"
|
12
|
+
builder.c %q{
|
13
|
+
VALUE values(){
|
14
|
+
|
15
|
+
struct data {
|
16
|
+
unsigned short x;
|
17
|
+
unsigned short y;
|
18
|
+
unsigned short z;
|
19
|
+
char pad[34];
|
20
|
+
};
|
21
|
+
|
22
|
+
kern_return_t result;
|
23
|
+
|
24
|
+
mach_port_t masterPort;
|
25
|
+
IOMasterPort(MACH_PORT_NULL, &masterPort);
|
26
|
+
CFMutableDictionaryRef matchingDictionary = IOServiceMatching("SMCMotionSensor");
|
27
|
+
|
28
|
+
io_iterator_t iterator;
|
29
|
+
result = IOServiceGetMatchingServices(masterPort, matchingDictionary, &iterator);
|
30
|
+
|
31
|
+
if(result != KERN_SUCCESS) {
|
32
|
+
return rb_str_new2("Error");
|
33
|
+
}
|
34
|
+
|
35
|
+
io_object_t device = IOIteratorNext(iterator);
|
36
|
+
IOObjectRelease(iterator);
|
37
|
+
if(device == 0){
|
38
|
+
return rb_str_new2("Error");
|
39
|
+
}
|
40
|
+
|
41
|
+
io_connect_t dataPort;
|
42
|
+
result = IOServiceOpen(device, mach_task_self(), 0, &dataPort);
|
43
|
+
IOObjectRelease(device);
|
44
|
+
|
45
|
+
if(result != KERN_SUCCESS) {
|
46
|
+
return rb_str_new2("Error");
|
47
|
+
}
|
48
|
+
|
49
|
+
IOItemCount structureInputSize;
|
50
|
+
IOByteCount structureOutputSize;
|
51
|
+
|
52
|
+
struct data inputStructure;
|
53
|
+
struct data outputStructure;
|
54
|
+
structureInputSize = sizeof(struct data);
|
55
|
+
structureOutputSize = sizeof(struct data);
|
56
|
+
|
57
|
+
memset(&inputStructure, 1, sizeof(inputStructure));
|
58
|
+
memset(&outputStructure, 0, sizeof(outputStructure));
|
59
|
+
|
60
|
+
result = IOConnectMethodStructureIStructureO(
|
61
|
+
dataPort,
|
62
|
+
5,
|
63
|
+
structureInputSize,
|
64
|
+
&structureOutputSize,
|
65
|
+
&inputStructure,
|
66
|
+
&outputStructure
|
67
|
+
);
|
68
|
+
|
69
|
+
if(result != KERN_SUCCESS) {
|
70
|
+
return rb_str_new2("Error");
|
71
|
+
}
|
72
|
+
|
73
|
+
IOServiceClose(dataPort);
|
74
|
+
|
75
|
+
VALUE coords = rb_ary_new2(3);
|
76
|
+
rb_ary_store(coords, 0, INT2FIX(outputStructure.x));
|
77
|
+
rb_ary_store(coords, 1, INT2FIX(outputStructure.y));
|
78
|
+
rb_ary_store(coords, 2, INT2FIX(outputStructure.z));
|
79
|
+
|
80
|
+
return coords;
|
81
|
+
}
|
82
|
+
}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.fixnum_is_negative? s
|
88
|
+
(s & 0x8000) != 0
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.fixnum_to_negative s
|
92
|
+
s - 0xFFFF
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.to_tilt s
|
96
|
+
signed = fixnum_is_negative?(s) ? fixnum_to_negative(s) : s
|
97
|
+
signed += 0xFF
|
98
|
+
signed < 0 ? 0 : signed
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.tilt_handicap_seconds
|
102
|
+
to_tilt(SMS.values.first) * 0.002
|
103
|
+
end
|
104
|
+
|
105
|
+
module ProgressBarFormatter
|
106
|
+
module InstanceExtension
|
107
|
+
%w[failed passed].each do |method|
|
108
|
+
define_method "example_#{method}" do |*args|
|
109
|
+
super *args
|
110
|
+
sleep RspecPrank.tilt_handicap_seconds
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
module ClassExtension
|
116
|
+
def new *args
|
117
|
+
(super *args).extend RspecPrank::ProgressBarFormatter::InstanceExtension
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
Spec::Runner::Formatter::ProgressBarFormatter.extend RspecPrank::ProgressBarFormatter::ClassExtension
|
124
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec_prank
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Cadenas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-09 00:00:00 -03:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: RubyInline
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: dcadenas@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
- LICENSE
|
34
|
+
files:
|
35
|
+
- LICENSE
|
36
|
+
- Rakefile
|
37
|
+
- README.rdoc
|
38
|
+
- VERSION.yml
|
39
|
+
- lib/rspec_prank.rb
|
40
|
+
- spec/pranked_spec.rb
|
41
|
+
- spec/spec_helper.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/dcadenas/rspec_prank
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --inline-source
|
49
|
+
- --charset=UTF-8
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.3.3
|
68
|
+
signing_key:
|
69
|
+
specification_version: 2
|
70
|
+
summary: RSpec + Apple Motion Sensor = Fun
|
71
|
+
test_files: []
|
72
|
+
|