frasco 0.1.0

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.
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Documentation cache and generated files:
13
+ /.yardoc/
14
+ /_yardoc/
15
+ /doc/
16
+ /rdoc/
17
+
18
+ ## Environment normalisation:
19
+ /.bundle/
20
+ /lib/bundler/man/
21
+
22
+ # for a library or gem, you might want to ignore these files since the code is
23
+ # intended to run in multiple environments; otherwise, check them in:
24
+ Gemfile.lock
25
+ .ruby-version
26
+ .ruby-gemset
27
+
28
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
29
+ .rvmrc
30
+
31
+ # bundler
32
+ /.bundle
33
+ /vendor/bundle
34
+
35
+ .frasco
36
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in frasco.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 NEET
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,62 @@
1
+ # frasco
2
+
3
+ Test environment manager for iOS simulator.
4
+
5
+ ## Installation
6
+
7
+ $ gem install frasco
8
+
9
+ ## Create Snapshot of Test Environment
10
+
11
+ ### 1. Initialize for your project
12
+
13
+ $ frasco init
14
+
15
+ `init` subcommand create `.frasco` directory in current directory.
16
+
17
+ ### 2. Backup the current iOS simulator environment and clear
18
+
19
+ $ frasco stash
20
+
21
+ If iOS simulator is running, execute with `--quit` option.
22
+
23
+ ### 3. Run iOS simulator, and make environment do as you wish
24
+
25
+ $ frasco simulator run
26
+
27
+ Example: Register Twitter accounts.
28
+
29
+ If you need a clean environment, you do not need to do anything.
30
+
31
+ ### 4. Save the snapshot
32
+
33
+ $ frasco save MySnapshot
34
+
35
+ ### 5. Cleanup and restore 1st step's backup
36
+
37
+ $ frasco cleanup --quit
38
+
39
+ ## Test Using the Snapshot
40
+
41
+ ### 1. Restore the snapshot
42
+
43
+ $ frasco up MySnapshot
44
+
45
+ `up` subcommand backup the current environment before restoration.
46
+
47
+ ### 2. Test on iOS simulator
48
+
49
+ Test by Xcode or xcodebuild, or manually…
50
+
51
+ ### 3. Cleanup and restore 1st step's backup
52
+
53
+ $ frasco cleanup --quit
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create new Pull Request
62
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if $PROGRAM_NAME == __FILE__
4
+ ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
5
+ require "rubygems"
6
+ require "bundler/setup"
7
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
8
+ end
9
+
10
+ require 'frasco/cli'
11
+
12
+ begin
13
+ Frasco::CLI.start
14
+ rescue Frasco::FrascoError => e
15
+ puts "Error: #{e.message}"
16
+ exit 1
17
+ end
18
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'frasco/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "frasco"
8
+ spec.version = Frasco::VERSION
9
+ spec.authors = ["mtmta"]
10
+ spec.email = ["d.masamoto@covelline.com"]
11
+ spec.summary = %q{Test environment manager for iOS simulator.}
12
+ spec.description = %q{Create a snapshot of the test environment for iOS simulator.}
13
+ spec.homepage = "http://neethouse.org/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "thor"
24
+ end
@@ -0,0 +1 @@
1
+ require "frasco/version"
@@ -0,0 +1,269 @@
1
+ require "Find"
2
+ require "thor"
3
+ require "frasco/version"
4
+ require "frasco/error"
5
+ require "frasco/snapshot"
6
+ require "frasco/simulator"
7
+
8
+ module Frasco
9
+
10
+ module PresetMethodOption
11
+
12
+ def preset_method_option(*options)
13
+
14
+ if options.include?(:quit)
15
+ method_option :quit,
16
+ :type => :boolean,
17
+ :aliases => "-q",
18
+ :desc => "Quit simulator before execute command."
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
25
+
26
+ class CLI < Thor
27
+
28
+ extend PresetMethodOption
29
+
30
+ package_name :frasco
31
+
32
+ @@STASH_NAME = "__stashed"
33
+
34
+ def initialize(*args)
35
+ super(*args)
36
+
37
+ @simulator_dir = File.expand_path("~/Library/Application Support/iPhone Simulator");
38
+ end
39
+
40
+
41
+ #######################################
42
+
43
+ desc "init", "Create '.frasco' directory in current location"
44
+ def init
45
+
46
+ raise FrascoError.new("already initialized") \
47
+ if File.exists?(".frasco")
48
+
49
+ FileUtils.mkdir(".frasco")
50
+ end
51
+
52
+
53
+ #######################################
54
+
55
+ desc "list", "Show saved snapshots"
56
+
57
+ def list
58
+
59
+ pattern = "#{_find_snapshots_dir}/*"
60
+
61
+ Dir.glob(pattern).sort.map do |path|
62
+ snapshot = _get_snapshot(Snapshot.unescape_name(File.basename(path)))
63
+
64
+ puts "#{snapshot.name}\t(#{snapshot.find_versions.join(', ')})"
65
+
66
+ end
67
+ end
68
+
69
+
70
+ #######################################
71
+
72
+ desc "save <NAME>", "Save snapshot with specified snapshot"
73
+
74
+ preset_method_option :quit
75
+
76
+ def save(name)
77
+
78
+ _before_bang_command
79
+
80
+ raise FrascoError.simulator_notfound_error \
81
+ unless File.exists?(@simulator_dir)
82
+
83
+ snapshot = _get_snapshot(name)
84
+
85
+ raise FrascoError.snapshot_exists_error(snapshot) \
86
+ if snapshot.exists?
87
+
88
+ _mkdir_parents(snapshot.path)
89
+
90
+ FileUtils.copy_entry(@simulator_dir, snapshot.path)
91
+ end
92
+
93
+
94
+ #######################################
95
+
96
+ desc "stash", "Backup current environment to stash, and destroy environment"
97
+
98
+ preset_method_option :quit
99
+
100
+ def stash
101
+
102
+ _before_bang_command
103
+
104
+ stash = _get_snapshot(@@STASH_NAME)
105
+
106
+ raise FrascoError.simulator_notfound_error \
107
+ unless File.exists?(@simulator_dir)
108
+
109
+ raise FrascoError.new("already stashed") \
110
+ if File.exists?(stash.path)
111
+
112
+ _mkdir_parents(stash.path)
113
+
114
+ FileUtils.move(@simulator_dir, stash.path)
115
+ end
116
+
117
+
118
+ #######################################
119
+
120
+ desc "up <NAME>", "Backup current environment to stash, and restore snapshot"
121
+
122
+ preset_method_option :quit
123
+
124
+ def up(name)
125
+
126
+ _before_bang_command
127
+
128
+ snapshot = _get_snapshot(name)
129
+
130
+ raise FrascoError.snapshot_notfound_error(snapshot) \
131
+ unless snapshot.exists?
132
+
133
+ stash
134
+
135
+ FileUtils.copy_entry(snapshot.path, @simulator_dir)
136
+ end
137
+
138
+
139
+ #######################################
140
+
141
+ desc "cleanup", "Destroy current simulator environment and restore stashed environment"
142
+
143
+ preset_method_option :quit
144
+
145
+ def cleanup
146
+
147
+ _before_bang_command
148
+
149
+ snapshot = _get_snapshot(@@STASH_NAME)
150
+
151
+ raise FrascoError.new("not stashed") \
152
+ unless snapshot.exists?
153
+
154
+ # nothing if not eixsts simulator dir
155
+ FileUtils.remove_dir(@simulator_dir) \
156
+ if File.exists?(@simulator_dir)
157
+
158
+ FileUtils.move(snapshot.path, @simulator_dir)
159
+
160
+ end
161
+
162
+
163
+ #######################################
164
+
165
+ desc "rename <ORG_NAME> <NEW_NAME>", "Change snapshot name"
166
+ def rename(org_name, new_name)
167
+
168
+ org_snapshot = _get_snapshot(org_name)
169
+
170
+ raise FrascoError.snapshot_notfound_error(org_snapshot) \
171
+ unless File.exists?(org_snapshot.path)
172
+
173
+ new_snapshot = _get_snapshot(new_name)
174
+
175
+ raise FrascoError.snapshot_exists_error(new_snapshot) \
176
+ if File.exists?(new_snapshot.path)
177
+
178
+ FileUtils.move(org_snapshot.path, new_snapshot.path)
179
+ end
180
+
181
+
182
+ #######################################
183
+
184
+ desc "remove <NAME>", "Remove snapshot"
185
+ def remove(name)
186
+
187
+ snapshot = _get_snapshot(name)
188
+
189
+ raise FrascoError.snapshot_notfound_error(snapshot) \
190
+ unless snapshot.exists?
191
+
192
+ FileUtils.remove_dir(snapshot.path)
193
+ end
194
+
195
+
196
+ #######################################
197
+
198
+ desc "simulator [COMMAND]", SimulatorCLI::DESC
199
+
200
+ def simulator(*args)
201
+ Frasco::SimulatorCLI.start(args)
202
+ end
203
+
204
+
205
+ #######################################
206
+
207
+ desc "version", "Show version"
208
+
209
+ def version
210
+ @shell.say("frasco version #{Frasco::VERSION} (c) 2013 neethouse.org")
211
+ end
212
+
213
+
214
+ #######################################
215
+
216
+ # Raise error if simulator is already running.
217
+ # Quit simulator if specified --quit option, and continue.
218
+ private
219
+ def _before_bang_command
220
+
221
+ simulator = Simulator.new
222
+
223
+ if simulator.is_running?
224
+ if options[:quit]
225
+ simulator.quit
226
+ else
227
+ raise FrascoError.new("Simulator is running. Quit with --quit option.")
228
+ end
229
+ end
230
+ end
231
+
232
+
233
+ private
234
+ def _get_snapshot(name)
235
+ Snapshot.new(_find_snapshots_dir, name)
236
+ end
237
+
238
+
239
+ # Create parent directories of specified path.
240
+ private
241
+ def _mkdir_parents(path)
242
+ basedir = File.dirname(path)
243
+ FileUtils.mkdir_p(basedir) unless File.exists?(basedir)
244
+ end
245
+
246
+
247
+ # Find .frasco directory from current dir to parent.
248
+ private
249
+ def _find_frasco_dir
250
+
251
+ dir = Dir::pwd
252
+
253
+ while !File::exists? frasco_dir = dir + "/.frasco"
254
+ dir = File::expand_path("..", dir);
255
+ raise FrascoError.new(".frasco directory not exists\nPlease execute 'frasco init' command.") if dir == "/"
256
+ end
257
+
258
+ frasco_dir
259
+ end
260
+
261
+ private
262
+ def _find_snapshots_dir
263
+ _find_snapshots_dir = "#{_find_frasco_dir}/snapshots"
264
+ end
265
+
266
+ end
267
+
268
+ end
269
+
@@ -0,0 +1,22 @@
1
+ require 'Find'
2
+ require "thor"
3
+
4
+ module Frasco
5
+
6
+ class FrascoError < StandardError
7
+
8
+ def self.simulator_notfound_error
9
+ self.new("simulator environment does not exists")
10
+ end
11
+
12
+ def self.snapshot_exists_error(snapshot)
13
+ self.new("specified snapshot is already exists: #{snapshot.name}")
14
+ end
15
+
16
+ def self.snapshot_notfound_error(snapshot)
17
+ self.new("no such snapshot: #{snapshot.name}")
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,84 @@
1
+ require "thor"
2
+ require "frasco/error"
3
+
4
+ module Frasco
5
+
6
+ class Simulator
7
+
8
+ @@SIMULATOR_PATH = "/Applications/Xcode.app/Contents/Applications/iPhone Simulator.app"
9
+
10
+ def run
11
+
12
+ raise FrascoError.new("Simulator not installed at '#{path}'") \
13
+ unless File.exists?(@@SIMULATOR_PATH)
14
+
15
+ `open "#{@@SIMULATOR_PATH}"`
16
+ end
17
+
18
+
19
+ def quit
20
+
21
+ `killall 'iPhone Simulator'`
22
+
23
+ while is_running?
24
+ sleep(0.2)
25
+ end
26
+ end
27
+
28
+
29
+ def is_running?
30
+ !`ps x | grep "[i]Phone Simulator.app"`.empty?
31
+ end
32
+
33
+ end
34
+
35
+
36
+ class SimulatorCLI < Thor
37
+
38
+ DESC = "Operate simulator. Available subcommands: run/quit/state"
39
+
40
+ def initialize(*args)
41
+ super(*args)
42
+
43
+ @simulator = Simulator.new
44
+ end
45
+
46
+
47
+ #######################################
48
+
49
+ desc "run", "Run or activate simulator"
50
+
51
+ def run_simulator
52
+ @simulator.run
53
+ end
54
+
55
+
56
+ #######################################
57
+
58
+ desc "quit", "Quit simulator"
59
+
60
+ def quit
61
+
62
+ raise FrascoError.new("Simulator is not running.") \
63
+ unless @simulator.is_running?
64
+
65
+ @simulator.quit
66
+ end
67
+
68
+
69
+ #######################################
70
+
71
+ desc "state", "Show simulator state ('running' or 'not running')"
72
+
73
+ def state
74
+ if @simulator.is_running?
75
+ puts "running"
76
+ else
77
+ puts "not running"
78
+ end
79
+ end
80
+
81
+ end
82
+
83
+ end
84
+
@@ -0,0 +1,41 @@
1
+
2
+ module Frasco
3
+
4
+ class Snapshot
5
+
6
+ attr_reader :name, :path
7
+
8
+ def initialize(root_dir, name)
9
+ @name = name
10
+ @path = "#{root_dir}/#{escaped_name}"
11
+ end
12
+
13
+ def escaped_name
14
+ self.class.escape_name(@name)
15
+ end
16
+
17
+ def exists?
18
+ File.exists?(@path)
19
+ end
20
+
21
+
22
+ def find_versions
23
+ Dir.glob("#{path}/*").map {|path| File.basename(path) }.sort
24
+ end
25
+
26
+
27
+ class << self
28
+
29
+ def escape_name(name)
30
+ name.gsub(%r(/), '-##-')
31
+ end
32
+
33
+ def unescape_name(name)
34
+ name.gsub(/-##-/, '/')
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,3 @@
1
+ module Frasco
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: frasco
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - mtmta
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: thor
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Create a snapshot of the test environment for iOS simulator.
63
+ email:
64
+ - d.masamoto@covelline.com
65
+ executables:
66
+ - frasco
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - LICENSE
73
+ - README.md
74
+ - Rakefile
75
+ - bin/frasco
76
+ - frasco.gemspec
77
+ - lib/frasco.rb
78
+ - lib/frasco/cli.rb
79
+ - lib/frasco/error.rb
80
+ - lib/frasco/simulator.rb
81
+ - lib/frasco/snapshot.rb
82
+ - lib/frasco/version.rb
83
+ homepage: http://neethouse.org/
84
+ licenses:
85
+ - MIT
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 1.8.23
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Test environment manager for iOS simulator.
108
+ test_files: []