fake_droid 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/Gemfile +2 -0
  2. data/LICENSE +0 -0
  3. data/README.md +11 -0
  4. data/Rakefile +117 -0
  5. data/fake_droid.gemspec +50 -0
  6. data/lib/fake_droid.rb +41 -0
  7. metadata +81 -0
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gem :faker, '0.3.1'
data/LICENSE ADDED
File without changes
@@ -0,0 +1,11 @@
1
+ > These aren't the droids you're looking for.
2
+
3
+ fake-droid is a small Ruby library for generating test data in the Android
4
+ emulator (At the moment only SMS).
5
+
6
+ ### Synopsis
7
+
8
+ $ gem install fake_droid
9
+ require 'fake_droid'
10
+ droid = FakeDroid.new
11
+ 10.times { droid.fake_sms }
@@ -0,0 +1,117 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def version
16
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def date
21
+ Date.today.to_s
22
+ end
23
+
24
+ def rubyforge_project
25
+ name
26
+ end
27
+
28
+ def gemspec_file
29
+ "#{name}.gemspec"
30
+ end
31
+
32
+ def gem_file
33
+ "#{name}-#{version}.gem"
34
+ end
35
+
36
+ def replace_header(head, header_name)
37
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38
+ end
39
+
40
+ #############################################################################
41
+ #
42
+ # Standard tasks
43
+ #
44
+ #############################################################################
45
+
46
+ task :default => :test
47
+
48
+ desc "Open an irb session preloaded with this library"
49
+ task :console do
50
+ sh "irb -rubygems -r ./lib/#{name}.rb"
51
+ end
52
+
53
+
54
+
55
+ #############################################################################
56
+ #
57
+ # Packaging tasks
58
+ #
59
+ #############################################################################
60
+
61
+ task :release => :build do
62
+ unless `git branch` =~ /^\* master$/
63
+ puts "You must be on the master branch to release!"
64
+ exit!
65
+ end
66
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
67
+ sh "git tag v#{version}"
68
+ sh "git push origin master --tags"
69
+ sh "gem push pkg/#{name}-#{version}.gem"
70
+ end
71
+
72
+ desc "Builds the gem"
73
+ task :build => :gemspec do
74
+ sh "mkdir -p pkg"
75
+ sh "gem build #{gemspec_file}"
76
+ sh "mv #{gem_file} pkg"
77
+ end
78
+
79
+ task :gemspec => :validate do
80
+ # read spec file and split out manifest section
81
+ spec = File.read(gemspec_file)
82
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
83
+
84
+ # replace name version and date
85
+ replace_header(head, :name)
86
+ replace_header(head, :version)
87
+ replace_header(head, :date)
88
+ #comment this out if your rubyforge_project has a different name
89
+ replace_header(head, :rubyforge_project)
90
+
91
+ # determine file list from git ls-files
92
+ files = `git ls-files`.
93
+ split("\n").
94
+ sort.
95
+ reject { |file| file =~ /^\./ }.
96
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
97
+ map { |file| " #{file}" }.
98
+ join("\n")
99
+
100
+ # piece file back together and write
101
+ manifest = " s.files = %w[\n#{files}\n ]\n"
102
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
103
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
104
+ puts "Updated #{gemspec_file}"
105
+ end
106
+
107
+ task :validate do
108
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb"]
109
+ unless libfiles.empty?
110
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
111
+ exit!
112
+ end
113
+ unless Dir['VERSION*'].empty?
114
+ puts "A `VERSION` file at root level violates Gem best practices."
115
+ exit!
116
+ end
117
+ end
@@ -0,0 +1,50 @@
1
+ Gem::Specification.new do |s|
2
+ s.specification_version = 2 if s.respond_to? :specification_version=
3
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
+ s.rubygems_version = '1.3.5'
5
+
6
+ ## Leave these as is they will be modified for you by the rake gemspec task.
7
+ ## If your rubyforge_project name is different, then edit it and comment out
8
+ ## the sub! line in the Rakefile
9
+ s.name = 'fake_droid'
10
+ s.version = '0.0.1'
11
+ s.date = '2010-08-07'
12
+ s.rubyforge_project = 'fake_droid'
13
+
14
+ ## Make sure your summary is short. The description may be as long
15
+ ## as you like.
16
+ s.summary = "Fake data generator for Android"
17
+ s.description = "Create fake data in an Android emulator (for dev purposes)"
18
+
19
+ ## List the primary authors. If there are a bunch of authors, it's probably
20
+ ## better to set the email to an email list or something. If you don't have
21
+ ## a custom homepage, consider using your GitHub URL or the like.
22
+ s.authors = ["Jan Berkel"]
23
+ s.email = 'jan.berkel@gmail.com'
24
+ s.homepage = 'http://github.com/jberkel/fake-droid'
25
+
26
+ s.require_paths = %w[lib]
27
+
28
+ s.rdoc_options = ["--charset=UTF-8"]
29
+ s.extra_rdoc_files = %w[README.md LICENSE]
30
+
31
+ s.add_dependency('faker', [">= 0.3.1"])
32
+
33
+ ## Leave this section as-is. It will be automatically generated from the
34
+ ## contents of your Git repository via the gemspec task. DO NOT REMOVE
35
+ ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
36
+ # = MANIFEST =
37
+ s.files = %w[
38
+ Gemfile
39
+ LICENSE
40
+ README.md
41
+ Rakefile
42
+ fake_droid.gemspec
43
+ lib/fake_droid.rb
44
+ ]
45
+ # = MANIFEST =
46
+
47
+ ## Test files will be grabbed from the file list. Make sure the path glob
48
+ ## matches what you actually use.
49
+ s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
50
+ end
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'faker'
5
+ require 'socket'
6
+
7
+ class FakeDroid
8
+ VERSION = '0.0.1'
9
+ attr_accessor :connection
10
+
11
+ def initialize(port = 5554)
12
+ @connection = begin
13
+ s = TCPSocket.open('localhost', port)
14
+ welcome = s.gets
15
+ check_status(s)
16
+ end
17
+ end
18
+
19
+ def check_status(socket)
20
+ status = socket.gets.chop
21
+ raise "Invalid status: #{status}" unless status =~ /\AOK/
22
+ socket
23
+ end
24
+
25
+ def command(cmd, *args)
26
+ connection.puts [cmd, *args].join ' '
27
+ check_status(connection)
28
+ end
29
+
30
+ def send_sms(from, body)
31
+ command("sms send", from, body)
32
+ end
33
+
34
+ def fake_sms
35
+ send_sms(Faker.numerify("+#########"), Faker::Lorem.sentences(2))
36
+ end
37
+ end
38
+
39
+ if __FILE__ == $0
40
+ FakeDroid.new.send_sms("123", 'check')
41
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fake_droid
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Jan Berkel
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-07 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: faker
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 3
30
+ - 1
31
+ version: 0.3.1
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: Create fake data in an Android emulator (for dev purposes)
35
+ email: jan.berkel@gmail.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - README.md
42
+ - LICENSE
43
+ files:
44
+ - Gemfile
45
+ - LICENSE
46
+ - README.md
47
+ - Rakefile
48
+ - fake_droid.gemspec
49
+ - lib/fake_droid.rb
50
+ has_rdoc: true
51
+ homepage: http://github.com/jberkel/fake-droid
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --charset=UTF-8
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project: fake_droid
76
+ rubygems_version: 1.3.6
77
+ signing_key:
78
+ specification_version: 2
79
+ summary: Fake data generator for Android
80
+ test_files: []
81
+