bwoken 1.3.0 → 2.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,38 +7,38 @@ Supports coffeescript and javascript.
7
7
  ![screenshot](https://raw.github.com/bendyworks/bwoken/master/doc/screenshot.png)
8
8
 
9
9
 
10
- ## Usage
10
+ ## On the Command Line
11
11
 
12
12
  ### Running tests
13
13
 
14
14
  Make sure bwoken is <a href="#installation">properly installed</a>. Then, build your project and run all your tests via:
15
15
 
16
16
  <pre><code># will build and run all of your tests
17
- $ rake
17
+ $ bwoken test
18
18
 
19
- # will run one file, relative to integration/coffeescript (note: no file extension)
20
- $ RUN=iphone/focused_test rake
19
+ # will run one file, relative to integration/coffeescript/{iphone,ipad}/
20
+ # (note: no file extension)
21
+ $ bwoken test --focus some_test # runs this test on (iphone and ipad) OR (connected iDevice)
22
+ $ bwoken test --focus some_test --family iphone
21
23
  </code></pre>
22
24
 
23
25
  ### Simulator or Device?
24
26
 
25
27
  To run bwoken tests on your device, just plug it in! And if you want to run tests in the simulator, just unplug it!
26
28
 
27
- As of bwoken 1.2.0, you can pass <code>SIMULATOR=true</code> as an environment variable to force simulator use even if your device is plugged in:
28
-
29
29
  <pre><code># without a device connected, will run on the simulator:
30
- $ rake
30
+ $ bwoken test
31
31
 
32
32
  # with a device connected, will run on the device:
33
- $ rake
33
+ $ bwoken test
34
34
 
35
35
  # with a device connected, will run on the simulator:
36
- $ SIMULATOR=true rake
36
+ $ bwoken test --simulator
37
37
  </code></pre>
38
38
 
39
39
  Your tests will look something like this:
40
40
 
41
- <pre><code>$ rake
41
+ <pre><code>$ bwoken test
42
42
  Building.............................................................................
43
43
  .....................................................................................
44
44
  .....................................................................................
@@ -73,21 +73,42 @@ Complete
73
73
  Duration: 23.419741s
74
74
  </code></pre>
75
75
 
76
- ### Bring in Libraries!
77
-
78
- Wanna bring in [tuneup.js](https://github.com/alexvollmer/tuneup_js) or [mechanic](https://github.com/jaykz52/mechanic)? Just use `#github` instead of `#import`:
79
-
80
- <pre><code>#github "alexvollmer/tuneup_js/tuneup.js"
81
- #github "jaykz52/mechanic/src/mechanic-core.js"
76
+ ### All the switches
77
+
78
+ Here's a list of all the switches that bwoken takes for the `test` command:
79
+
80
+ <pre><code>
81
+ $ bwoken test -h
82
+ [...]
83
+ --simulator Use simulator, even when an iDevice is connected
84
+ --family Test only one device type, either ipad or iphone. Default is to test on both
85
+ --scheme Specify a custom scheme
86
+ --formatter Specify a custom formatter (e.g., --formatter=passthru)
87
+ --focus Specify particular tests to run
88
+ --clobber Remove any generated file
89
+ --skip-build Do not build the iOS binary
90
+ --verbose Be verbose
91
+ -h, --help Display this help message.
82
92
  </code></pre>
83
93
 
94
+ ## In Your Code
95
+
84
96
  ### Like Javascript?
85
97
 
86
- Sometimes we'd like to have some javascript help us out. For example, what if you'd like <a href="http://underscorejs.org">Underscore.js</a> in your test suite? Simple! Just put it in <code>integration/javascript</code> and import it in your test:
98
+ Sometimes we'd like to have some javascript help us out. For example, what if you'd like [Underscore.js](http://underscorejs.org) in your test suite? Simple! Just put it in <code>integration/javascript</code> and import it in your test:
87
99
 
88
100
  <pre><code>#import "../underscore.js"
89
101
  </code></pre>
90
102
 
103
+ ### Bring in Libraries!
104
+
105
+ Wanna bring in [tuneup.js](https://github.com/alexvollmer/tuneup_js), [mechanic](https://github.com/jaykz52/mechanic), or [underscore](http://underscorejs.org) without manually downloading them first? Just use `#github` instead of `#import`:
106
+
107
+ <pre><code>#github "jashkenas/underscore/underscore.js"
108
+ #github "alexvollmer/tuneup_js/tuneup.js"
109
+ #github "jaykz52/mechanic/src/mechanic-core.js"
110
+ </code></pre>
111
+
91
112
 
92
113
  ## Installation
93
114
 
@@ -100,7 +121,7 @@ Ensure your project is in a workspace rather than simply a project:
100
121
  * In Xcode, select File -&gt; Save as workspace...
101
122
  * Save the workspace in the same directory as your .xcodeproj file
102
123
 
103
- Note: This is done automatically if you use <a href="http://cocoapods.org/">CocoaPods</a>. I highly suggest you do!
124
+ Note: This is done automatically if you use [CocoaPods](http://cocoapods.org/). I highly suggest you do!
104
125
 
105
126
  ### Prerequisites
106
127
 
@@ -111,18 +132,18 @@ Install rvm via <a href="https://rvm.io/rvm/install/">the instructions</a>. Ensu
111
132
  <pre><code>$ chmod u+x ~/.rvm/hooks/after_cd_bundler
112
133
  </code></pre>
113
134
 
114
- ### Installation
135
+ ### Install
115
136
 
116
137
  In the terminal, inside the directory of your project (e.g., you should see a <code>ProjectName.xcodeproj</code> file), create an <code>.rvmrc</code> file and trigger its use:
117
138
 
118
- <pre><code>$ echo 'rvm use 1.9.3@my_project' &gt; .rvmrc
119
- $ rvm rvmrc trust .rvmrc
120
- $ . .rvmrc
139
+ <pre><code>$ echo '2.0.0' &gt; .ruby-version
140
+ $ echo 'my_project' &gt; .ruby-gemset
141
+ $ cd .
121
142
  </code></pre>
122
143
 
123
144
  Install bundler (a ruby library dependency manager) and init:
124
145
 
125
- <pre><code>$ gem install bundler
146
+ <pre><code>$ gem install bundler # idempotent; might already be installed and that's ok
126
147
  $ bundle init
127
148
  </code></pre>
128
149
 
@@ -132,14 +153,17 @@ This will create a <code>Gemfile</code>. Add bwoken to it and bundle:
132
153
  $ bundle
133
154
  </code></pre>
134
155
 
135
- Then, create a simple <code>Rakefile</code> and initialize your bwoken file structure:
156
+ The last installation step is to initialize the bwoken file structure:
136
157
 
137
- <pre><code>$ echo "require 'bwoken/tasks'" &gt; Rakefile
138
- $ rake bwoken:init
158
+ <pre><code>$ bwoken init
139
159
  </code></pre>
140
160
 
141
161
  Now, you can start <a href="#usage">using it!</a>
142
162
 
163
+ #### The Dirty Little Installation Method
164
+
165
+ Technically, you can skip this entire Installation section and just run `sudo gem install bwoken && bwoken init`. This is listed here for completeness, but you really shouldn't install gems this way.
166
+
143
167
  ## Contributing
144
168
 
145
169
  1. Fork it
data/bin/bwoken ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bwoken/cli'
data/lib/bwoken/build.rb CHANGED
@@ -1,44 +1,56 @@
1
1
  require 'open3'
2
+ require 'bwoken'
2
3
  require 'bwoken/device'
3
4
 
4
5
  module Bwoken
6
+ class BuildFailedError < RuntimeError; end
7
+
5
8
  class Build
6
9
 
7
- def app_dir
8
- File.join(configuration_build_dir, "#{Bwoken.app_name}.app")
9
- end
10
+ class << self
11
+ def build_path
12
+ File.join(Bwoken.project_path, 'build')
13
+ end
10
14
 
11
- def build_path
12
- File.join(Bwoken.project_path, 'build')
13
- end
15
+ def xcconfig
16
+ File.join(File.dirname(__FILE__), 'configs', 'bwoken.xcconfig')
17
+ end
14
18
 
15
- def scheme
16
- Bwoken.app_name
17
- end
19
+ def sdk simulator
20
+ simulator ? 'iphonesimulator' : 'iphoneos'
21
+ end
18
22
 
19
- def configuration
20
- 'Debug'
21
- end
23
+ def configuration_build_dir simulator
24
+ File.join(build_path, sdk(simulator))
25
+ end
22
26
 
23
- def sdk
24
- if Bwoken::Device.should_use_simulator?
25
- 'iphonesimulator'
26
- else
27
- 'iphoneos'
27
+ def app_dir simulator
28
+ File.join(configuration_build_dir(simulator), "#{Bwoken.app_name}.app")
28
29
  end
29
30
  end
30
31
 
31
- def configuration_build_dir
32
- File.join(build_path, sdk)
32
+ #attr_accessor :flags #TODO: implement
33
+ attr_accessor :formatter
34
+ attr_accessor :scheme
35
+ attr_accessor :simulator
36
+ attr_accessor :configuration
37
+ attr_accessor :verbose
38
+
39
+ def initialize
40
+ #self.flags = [] #TODO: implement
41
+ self.scheme = Bwoken.app_name
42
+ self.configuration = 'Debug'
43
+
44
+ yield self if block_given?
33
45
  end
34
46
 
35
- def xcconfig
36
- File.join(File.dirname(__FILE__), 'configs', 'bwoken.xcconfig')
47
+ def sdk
48
+ self.class.sdk(simulator)
37
49
  end
38
50
 
39
51
  def env_variables
40
52
  {
41
- 'BWOKEN_CONFIGURATION_BUILD_DIR' => configuration_build_dir
53
+ 'BWOKEN_CONFIGURATION_BUILD_DIR' => self.class.configuration_build_dir(simulator)
42
54
  }
43
55
  end
44
56
 
@@ -46,35 +58,55 @@ module Bwoken
46
58
  env_variables.map{|key,val| "#{key}=#{val}"}.join(' ')
47
59
  end
48
60
 
61
+ def scheme_string
62
+ Bwoken.xcworkspace ? "-scheme #{scheme}" : ''
63
+ end
64
+
49
65
  def cmd
50
66
  "xcodebuild \
51
67
  #{Bwoken.workspace_or_project_flag} \
52
- #{"-scheme #{scheme}" if Bwoken.xcworkspace} \
68
+ #{scheme_string} \
53
69
  -configuration #{configuration} \
54
70
  -sdk #{sdk} \
55
- -xcconfig #{xcconfig} \
71
+ -xcconfig #{self.class.xcconfig} \
56
72
  #{variables_for_cli} \
57
73
  clean build"
58
74
  end
59
75
 
60
76
  def compile
61
- Bwoken.formatter.before_build_start
77
+ formatter.before_build_start
62
78
 
63
- exit_status = 0
64
- Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
79
+ succeeded, out_string, err_string = RUBY_VERSION == '1.8.7' ? compile_18 : compile_19_plus
65
80
 
66
- out_string = Bwoken.formatter.format_build stdout
81
+ if succeeded
82
+ formatter.build_successful out_string
83
+ else
84
+ formatter.build_failed out_string, err_string
85
+ fail BuildFailedError.new
86
+ end
87
+ end
88
+
89
+ def compile_18
90
+ out_string, err_string = '', ''
91
+ a, b, c = Open3.popen3(cmd) do |stdin, stdout, stderr|
92
+ out_string = formatter.format_build stdout
93
+ err_string = stderr.read
94
+ end
95
+
96
+ [a.to_s !~ /BUILD FAILED/, out_string, err_string]
97
+ end
98
+
99
+ def compile_19_plus
100
+ ret = nil
101
+ Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
67
102
 
103
+ out_string = formatter.format_build stdout
104
+ err_string = stderr.read
68
105
  exit_status = wait_thr.value if wait_thr
69
106
 
70
- if exit_status == 0 # Build Successful
71
- Bwoken.formatter.build_successful out_string
72
- else # Build Failed
73
- Bwoken.formatter.build_failed out_string, stderr.read
74
- return exit_status
75
- end
107
+ ret = [exit_status == 0, out_string, err_string]
76
108
  end
77
- exit_status
109
+ ret
78
110
  end
79
111
  end
80
112
  end
@@ -0,0 +1,48 @@
1
+ require 'fileutils'
2
+ require 'slop'
3
+
4
+ module Bwoken
5
+ module CLI
6
+ class Init
7
+
8
+ class << self
9
+
10
+ def help_banner
11
+ <<BANNER
12
+ Initialize your UIAutomation project.
13
+
14
+
15
+ == Options ==
16
+ BANNER
17
+ end
18
+ end
19
+
20
+ # opts - A slop command object (acts like super-hash)
21
+ # There are currently no options available
22
+ def initialize opts
23
+ # opts = opts.to_hash if opts.is_a?(Slop)
24
+ end
25
+
26
+ def run
27
+ directory 'integration/coffeescript/iphone'
28
+ directory 'integration/coffeescript/ipad'
29
+ directory 'integration/javascript'
30
+ directory 'integration/tmp/results'
31
+ template 'integration/coffeescript/iphone/example.coffee'
32
+ template 'integration/coffeescript/ipad/example.coffee'
33
+ template 'integration/javascript/example_vendor.js'
34
+ end
35
+
36
+ def directory dirname
37
+ FileUtils.mkdir_p dirname
38
+ end
39
+
40
+ def template filename
41
+ FileUtils.cp \
42
+ File.expand_path("../templates/#{filename}", __FILE__),
43
+ filename
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,5 @@
1
+ # iPad example test file
2
+ #import ../example_vendor.js
3
+
4
+ target = UIATarget.localTarget()
5
+ window = target.frontMostApp().mainWindow()
@@ -0,0 +1,5 @@
1
+ # iPhone example test file
2
+ #import ../example_vendor.js
3
+
4
+ target = UIATarget.localTarget()
5
+ window = target.frontMostApp().mainWindow()
@@ -0,0 +1,133 @@
1
+ require 'slop'
2
+ require 'rake/file_list'
3
+ require 'fileutils'
4
+
5
+ require 'bwoken'
6
+ require 'bwoken/build'
7
+ require 'bwoken/coffeescript'
8
+ require 'bwoken/device'
9
+ #TODO: make formatters dynamically loadable during runtime
10
+ require 'bwoken/formatter'
11
+ require 'bwoken/formatters/passthru_formatter'
12
+ require 'bwoken/formatters/colorful_formatter'
13
+ require 'bwoken/script_runner'
14
+
15
+ module Bwoken
16
+ module CLI
17
+ class Test
18
+
19
+ def self.help_banner
20
+ <<BANNER
21
+ Run your tests. If you don't specify which tests, bwoken will run them all
22
+
23
+ bwoken test --simulator # runs all tests in the simulator
24
+
25
+ You can specify a device family if you only want to run, say, iPad tests:
26
+
27
+ bwoken test --family ipad
28
+
29
+ If you only want to run a specific test, you can focus on it:
30
+
31
+ bwoken test --focus login # runs iPhone and iPad tests named "login"
32
+
33
+
34
+ == Options ==
35
+ BANNER
36
+ end
37
+
38
+ attr_accessor :options
39
+
40
+ # opts - A slop command object (acts like super-hash)
41
+ # :clobber - remove all generated files, including iOS build
42
+ # :family - enum of [nil, 'iphone', 'ipad'] (case-insensitive)
43
+ # :flags - custom build flag array (default: []) TODO: not yet implmented
44
+ # :focus - which tests to run (default: [], meaning "all")
45
+ # :formatter - custom formatter (default: 'colorful')
46
+ # :scheme - custom scheme (default: nil)
47
+ # :simulator - should force simulator use (default: nil)
48
+ # :skip-build - do not build the iOS binary
49
+ # :verbose - be verbose
50
+ def initialize opts
51
+ opts = opts.to_hash if opts.is_a?(Slop)
52
+ self.options = opts.to_hash.tap do |o|
53
+ o[:formatter] = 'passthru' if o[:verbose]
54
+ o[:formatter] = select_formatter(o[:formatter])
55
+ o[:simulator] = use_simulator?(o[:simulator])
56
+ o[:family] = o[:family]
57
+ end
58
+ end
59
+
60
+ def run
61
+ clobber if options[:clobber]
62
+ compile unless options[:'skip-build']
63
+ clean
64
+ transpile
65
+ test
66
+ end
67
+
68
+ def compile
69
+ Build.new do |b|
70
+ #b.flags = opts.flags #TODO: implement
71
+ b.formatter = options[:formatter]
72
+ b.scheme = options[:scheme] if options[:scheme]
73
+ b.simulator = options[:simulator]
74
+ end.compile
75
+ end
76
+
77
+ def transpile
78
+ coffeescripts = Rake::FileList['integration/coffeescript/**/*.coffee']
79
+ compiled_coffee = coffeescripts.pathmap('%{^integration/coffeescript,integration/tmp/javascript}d/%n.js')
80
+ javascripts = Rake::FileList['integration/javascript/**/*.js']
81
+ copied_javascripts = javascripts.pathmap('%{^integration/javascript,integration/tmp/javascript}d/%f')
82
+
83
+ compiled_coffee.zip(coffeescripts).each do |target, source|
84
+ containing_dir = target.pathmap('%d')
85
+ ensure_directory containing_dir
86
+ Bwoken::Coffeescript.compile source, target
87
+ end
88
+
89
+ copied_javascripts.zip(javascripts).each do |target, source|
90
+ containing_dir = target.pathmap('%d')
91
+ ensure_directory containing_dir
92
+ FileUtils.cp source, target
93
+ end
94
+ end
95
+
96
+ def test
97
+ ScriptRunner.new do |s|
98
+ s.app_dir = Build.app_dir(options[:simulator])
99
+ s.family = options[:family]
100
+ s.focus = options[:focus]
101
+ s.formatter = options[:formatter]
102
+ s.simulator = options[:simulator]
103
+ end.execute
104
+ end
105
+
106
+ def clobber
107
+ FileUtils.rm_rf Bwoken.tmp_path
108
+ FileUtils.rm_rf Bwoken::Build.build_path
109
+ end
110
+
111
+ def clean
112
+ FileUtils.rm_rf Bwoken.test_suite_path
113
+ end
114
+
115
+ def select_formatter formatter_name
116
+ case formatter_name
117
+ when 'passthru' then Bwoken::PassthruFormatter.new
118
+ else Bwoken::ColorfulFormatter.new
119
+ end
120
+ end
121
+
122
+ def use_simulator? want_forced_simulator
123
+ want_forced_simulator || ! Bwoken::Device.connected?
124
+ end
125
+
126
+ def ensure_directory dir
127
+ FileUtils.mkdir_p dir
128
+ end
129
+
130
+ end
131
+
132
+ end
133
+ end
data/lib/bwoken/cli.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'slop'
2
+
3
+ %w(version cli/init cli/test).each do |f|
4
+ require File.expand_path("../#{f}", __FILE__)
5
+ end
6
+
7
+ ran_command = nil
8
+
9
+ opts = Slop.parse :help => true do
10
+ on :v, :version, 'Print the version' do
11
+ puts Bwoken::VERSION
12
+ exit 0
13
+ end
14
+
15
+ command 'init' do
16
+ banner Bwoken::CLI::Init.help_banner
17
+
18
+ run { ran_command = 'init' }
19
+ end
20
+
21
+ command 'test' do
22
+ banner Bwoken::CLI::Test.help_banner
23
+
24
+ on :simulator, 'Use simulator, even when an iDevice is connected', :default => false
25
+
26
+ on :family=, 'Test only one device type, either ipad or iphone. Default is to test on both',
27
+ :match => /\A(?:ipad|iphone|all)\Z/i, :default => 'all'
28
+ on :scheme=, 'Specify a custom scheme'
29
+ #on :flags=, 'Specify custom build flags (e.g., --flags="-arch=i386,foo=bar")', :as => Array, :default => [] # TODO: implement
30
+ on :formatter=, 'Specify a custom formatter (e.g., --formatter=passthru)', :default => 'colorful'
31
+ on :focus=, 'Specify particular tests to run', :as => Array, :default => []
32
+ on :clobber, 'Remove any generated file'
33
+ on :'skip-build', 'Do not build the iOS binary'
34
+ on :verbose, 'Be verbose'
35
+
36
+ run { ran_command = 'test' }
37
+ end
38
+
39
+ end
40
+
41
+ if File.exists?('Rakefile')
42
+ contents = open('Rakefile').read.strip
43
+ if contents =~ /\Arequire ["']bwoken\/tasks["']\Z/
44
+ STDERR.puts 'You may safely delete Rakefile'
45
+ elsif contents =~ /require ["']bwoken\/tasks["']/
46
+ STDERR.puts %Q|You may safely remove the "require 'bwoken/tasks'" line from Rakefile|
47
+ end
48
+ end
49
+
50
+ case ran_command
51
+ when 'init' then Bwoken::CLI::Init.new(opts.commands['init']).run
52
+ when 'test' then Bwoken::CLI::Test.new(opts.commands['test']).run
53
+ else puts opts
54
+ end
data/lib/bwoken/device.rb CHANGED
@@ -2,10 +2,12 @@ module Bwoken
2
2
  class Device
3
3
  class << self
4
4
 
5
+ # deprecated. Remove when Rakefile support removed
5
6
  def should_use_simulator?
6
7
  want_simulator? || ! connected?
7
8
  end
8
9
 
10
+ # deprecated. Remove when Rakefile support removed
9
11
  def want_simulator?
10
12
  ENV['SIMULATOR'] && ENV['SIMULATOR'].downcase == 'true'
11
13
  end
@@ -15,10 +17,17 @@ module Bwoken
15
17
  end
16
18
 
17
19
  def uuid
18
- ioreg = `ioreg -w 0 -rc IOUSBDevice -k SupportsIPhoneOS`
19
20
  ioreg[/"USB Serial Number" = "([0-9a-z]+)"/] && $1
20
21
  end
21
22
 
23
+ def device_type
24
+ ioreg[/"USB Product Name" = "(.*)"/] && $1.downcase
25
+ end
26
+
27
+ def ioreg
28
+ @ioreg ||= `ioreg -w 0 -rc IOUSBDevice -k SupportsIPhoneOS`
29
+ end
30
+
22
31
  end
23
32
 
24
33
  end
@@ -0,0 +1,62 @@
1
+ require 'bwoken'
2
+ require 'bwoken/script'
3
+
4
+ module Bwoken
5
+ class DeviceRunner
6
+ attr_accessor :focus
7
+ attr_accessor :formatter
8
+ attr_accessor :app_dir
9
+
10
+ alias_method :feature_names, :focus
11
+
12
+ def initialize
13
+ yield self if block_given?
14
+ end
15
+
16
+ def execute
17
+ scripts.each(&:run)
18
+ end
19
+
20
+ def device_family
21
+ Device.device_type
22
+ end
23
+
24
+ def scripts
25
+ script_filenames.map do |filename|
26
+ Script.new do |s|
27
+ s.path = filename
28
+ s.device_family = device_family
29
+ s.formatter = formatter
30
+ s.app_dir = app_dir
31
+ end
32
+ end
33
+ end
34
+
35
+ def script_filenames
36
+ if focus.respond_to?(:length) && focus.length > 0
37
+ test_files_from_feature_names
38
+ else
39
+ all_test_files
40
+ end
41
+ end
42
+
43
+ def test_files_from_feature_names
44
+ feature_names.map do |feature_name|
45
+ File.join(Bwoken.test_suite_path, device_family, "#{feature_name}.js")
46
+ end
47
+ end
48
+
49
+ def all_test_files
50
+ all_files_in_test_dir - helper_files
51
+ end
52
+
53
+ def all_files_in_test_dir
54
+ Dir["#{Bwoken.test_suite_path}/#{device_family}/**/*.js"]
55
+ end
56
+
57
+ def helper_files
58
+ Dir["#{Bwoken.test_suite_path}/#{device_family}/**/helpers/**/*.js"]
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,12 @@
1
+ require 'bwoken/formatter'
2
+
3
+ module Bwoken
4
+ class PassthruFormatter < Formatter
5
+ [:before_build_start, :build_line, :build_successful, :build_failed,
6
+ :complete, :debug, :error, :fail, :other, :pass, :start].each do |cb|
7
+ on cb do |line|
8
+ puts line
9
+ end
10
+ end
11
+ end
12
+ end
data/lib/bwoken/script.rb CHANGED
@@ -1,47 +1,26 @@
1
1
  require 'fileutils'
2
2
  require 'open3'
3
3
 
4
- require 'bwoken/build'
4
+ require 'bwoken'
5
+ require 'bwoken/device'
5
6
 
6
7
  module Bwoken
7
-
8
8
  class ScriptFailedError < RuntimeError; end
9
9
 
10
10
  class Script
11
11
 
12
- attr_accessor :path
13
-
14
- class << self
15
-
16
- def run_all device_family
17
- Simulator.device_family = device_family
18
-
19
- test_files(device_family).each do |javascript|
20
- run(javascript)
21
- end
22
- end
23
-
24
- def run_one feature_name, device_family
25
- Simulator.device_family = device_family
26
- run File.join(Bwoken.test_suite_path, device_family, "#{feature_name}.js")
27
- end
28
-
29
- def run javascript_path
30
- script = new
31
- script.path = javascript_path
32
- script.run
33
- end
34
-
35
- def trace_file_path
36
- File.join(Bwoken.tmp_path, 'trace')
37
- end
12
+ def self.trace_file_path
13
+ File.join(Bwoken.tmp_path, 'trace')
14
+ end
38
15
 
39
- def test_files device_family
40
- all_files_in_test_dir = Dir["#{Bwoken.test_suite_path}/#{device_family}/**/*.js"]
41
- helper_files = Dir["#{Bwoken.test_suite_path}/#{device_family}/**/helpers/**/*.js"]
42
- all_files_in_test_dir - helper_files
43
- end
16
+ attr_accessor :path
17
+ attr_accessor :device_family
18
+ attr_accessor :formatter
19
+ attr_accessor :simulator
20
+ attr_accessor :app_dir
44
21
 
22
+ def initialize
23
+ yield self if block_given?
45
24
  end
46
25
 
47
26
  def env_variables
@@ -56,36 +35,25 @@ module Bwoken
56
35
  end
57
36
 
58
37
  def cmd
59
- build = Bwoken::Build.new
60
38
  "#{File.expand_path('../../../bin', __FILE__)}/unix_instruments.sh \
61
39
  #{device_flag} \
62
40
  -D #{self.class.trace_file_path} \
63
41
  -t #{Bwoken.path_to_automation_template} \
64
- #{build.app_dir} \
42
+ #{app_dir} \
65
43
  #{env_variables_for_cli}"
66
44
  end
67
45
 
68
46
  def device_flag
69
- if Bwoken::Device.should_use_simulator?
70
- ''
71
- else
72
- "-w #{Bwoken::Device.uuid}"
73
- end
74
- end
75
-
76
- def make_results_path_dir
77
- FileUtils.mkdir_p Bwoken.results_path
47
+ simulator ? '' : "-w #{Bwoken::Device.uuid}"
78
48
  end
79
49
 
80
50
  def run
81
- Bwoken.formatter.before_script_run path
82
- make_results_path_dir
51
+ formatter.before_script_run path
83
52
 
84
- exit_status = 0
85
53
  Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
86
- exit_status = Bwoken.formatter.format stdout
54
+ exit_status = formatter.format stdout
55
+ raise ScriptFailedError.new('Test Script Failed') unless exit_status == 0
87
56
  end
88
- raise ScriptFailedError.new('Test Script Failed') unless exit_status == 0
89
57
  end
90
58
 
91
59
  end
@@ -0,0 +1,67 @@
1
+ require 'bwoken/simulator_runner'
2
+ require 'bwoken/device_runner'
3
+
4
+ module Bwoken
5
+ class ScriptRunner
6
+ attr_accessor :family
7
+ attr_accessor :focus
8
+ attr_accessor :formatter
9
+ attr_accessor :simulator
10
+ attr_accessor :app_dir
11
+
12
+ alias_method :feature_names, :focus
13
+
14
+ def initialize
15
+ yield self if block_given?
16
+ end
17
+
18
+ def execute
19
+ if simulator
20
+ execute_in_simulator
21
+ else
22
+ execute_on_device
23
+ end
24
+ end
25
+
26
+ def execute_in_simulator
27
+ chosen_families.each do |device_family|
28
+ execute_for_family device_family
29
+ end
30
+ end
31
+
32
+ def execute_for_family device_family
33
+ runner_for_family(device_family).execute
34
+ end
35
+
36
+ def runner_for_family device_family
37
+ SimulatorRunner.new do |sr|
38
+ sr.device_family = device_family
39
+ sr.focus = focus
40
+ sr.formatter = formatter
41
+ sr.simulator = simulator
42
+ sr.app_dir = app_dir
43
+ end
44
+ end
45
+
46
+ def chosen_families
47
+ if family == 'all' || family == [] || family.nil?
48
+ %w(iphone ipad)
49
+ else
50
+ Array(family)
51
+ end
52
+ end
53
+
54
+ def execute_on_device
55
+ runner_for_device.execute
56
+ end
57
+
58
+ def runner_for_device
59
+ DeviceRunner.new do |dr|
60
+ dr.focus = focus
61
+ dr.formatter = formatter
62
+ dr.app_dir = app_dir
63
+ end
64
+ end
65
+
66
+ end
67
+ end
@@ -2,7 +2,7 @@ module Bwoken
2
2
  class Simulator
3
3
 
4
4
  def self.plist_buddy; '/usr/libexec/PlistBuddy'; end
5
- def self.plist_file; "#{Bwoken::Build.new.app_dir}/Info.plist"; end
5
+ def self.plist_file; "#{Bwoken::Build.app_dir(true)}/Info.plist"; end
6
6
 
7
7
  def self.device_family= device_family
8
8
  update_device_family_in_plist :delete_array
@@ -0,0 +1,63 @@
1
+ require 'bwoken'
2
+ require 'bwoken/script'
3
+ require 'bwoken/simulator'
4
+
5
+ module Bwoken
6
+ class SimulatorRunner
7
+ attr_accessor :focus
8
+ attr_accessor :formatter
9
+ attr_accessor :simulator
10
+ attr_accessor :app_dir
11
+ attr_accessor :device_family
12
+
13
+ alias_method :feature_names, :focus
14
+
15
+ def initialize
16
+ yield self if block_given?
17
+ end
18
+
19
+ def execute
20
+ Simulator.device_family = device_family
21
+ scripts.each(&:run)
22
+ end
23
+
24
+ def scripts
25
+ script_filenames.map do |filename|
26
+ Script.new do |s|
27
+ s.path = filename
28
+ s.device_family = device_family
29
+ s.formatter = formatter
30
+ s.simulator = simulator
31
+ s.app_dir = app_dir
32
+ end
33
+ end
34
+ end
35
+
36
+ def script_filenames
37
+ if focus.respond_to?(:length) && focus.length > 0
38
+ test_files_from_feature_names
39
+ else
40
+ all_test_files
41
+ end
42
+ end
43
+
44
+ def test_files_from_feature_names
45
+ feature_names.map do |feature_name|
46
+ File.join(Bwoken.test_suite_path, device_family, "#{feature_name}.js")
47
+ end
48
+ end
49
+
50
+ def all_test_files
51
+ all_files_in_test_dir - helper_files
52
+ end
53
+
54
+ def all_files_in_test_dir
55
+ Dir["#{Bwoken.test_suite_path}/#{device_family}/**/*.js"]
56
+ end
57
+
58
+ def helper_files
59
+ Dir["#{Bwoken.test_suite_path}/#{device_family}/**/helpers/**/*.js"]
60
+ end
61
+
62
+ end
63
+ end
@@ -1,72 +1,53 @@
1
1
  require 'bwoken'
2
2
  require 'rake/clean'
3
3
 
4
- COFFEESCRIPTS = FileList['integration/coffeescript/**/*.coffee']
5
- COMPILED_COFFEE = COFFEESCRIPTS.pathmap('%{^integration/coffeescript,integration/tmp/javascript}d/%n.js')
6
- JAVASCRIPTS = FileList['integration/javascript/**/*.js']
7
- COPIED_JAVASCRIPTS = JAVASCRIPTS.pathmap('%{^integration/javascript,integration/tmp/javascript}d/%f')
4
+ require 'slop'
5
+ require 'bwoken/cli/init'
6
+ require 'bwoken/cli/test'
8
7
 
9
8
  BUILD_DIR = 'build'
10
9
  IPHONE_DIR = 'integration/coffeescript/iphone'
11
- IPAD_DIR = 'integration/coffeescript/ipad'
12
10
  VENDOR_JS_DIR = 'integration/javascript'
13
11
  RESULTS_DIR = 'integration/tmp/results'
14
- EXAMPLE_COFFEE = 'integration/coffeescript/iphone/example.coffee'
15
- EXAMPLE_VENDOR_JS = 'integration/javascript/example_js.js'
16
12
 
17
13
  directory IPHONE_DIR
18
- directory IPAD_DIR
19
14
  directory VENDOR_JS_DIR
20
15
  directory RESULTS_DIR
21
16
  directory BUILD_DIR
22
17
 
23
- file EXAMPLE_COFFEE => IPHONE_DIR do |t|
24
- open(t.name, 'w') do |io|
25
- io.puts '#import ../example_js.js'
26
- io.puts 'target = UIATarget.localTarget()'
27
- io.puts 'window = target.frontMostApp().mainWindow()'
28
- end
29
- end
30
-
31
- file EXAMPLE_VENDOR_JS => VENDOR_JS_DIR do |t|
32
- open(t.name, 'w') do |io|
33
- io.puts '/* Place your javascript here */'
34
- end
18
+ task :rake_deprecated do
19
+ STDERR.puts 'WARNING: Invoking bwoken with rake is deprecated. Please use the `bwoken` executable now.'
20
+ STDERR.puts 'Please see https://github.com/bendyworks/bwoken/wiki/Upgrading-from-v1-to-v2'
21
+ STDERR.puts ''
35
22
  end
36
23
 
37
24
  namespace :bwoken do
38
25
  desc 'Create bwoken skeleton folders'
39
- task :init => [IPAD_DIR, RESULTS_DIR, EXAMPLE_COFFEE, EXAMPLE_VENDOR_JS]
40
- end
41
-
42
- COMPILED_COFFEE.zip(COFFEESCRIPTS).each do |target, source|
43
- containing_dir = target.pathmap('%d')
44
- directory containing_dir
45
- file target => [containing_dir, source] do
46
- Bwoken::Coffeescript.compile source, target
47
- end
48
- end
49
-
50
- COPIED_JAVASCRIPTS.zip(JAVASCRIPTS).each do |target, source|
51
- containing_dir = target.pathmap('%d')
52
- directory containing_dir
53
- file target => [containing_dir, source] do
54
- sh "cp #{source} #{target}"
26
+ task :init => :rake_deprecated do
27
+ Bwoken::CLI::Init.new({}).run
55
28
  end
56
29
  end
57
30
 
58
31
  desc 'Compile coffeescript to javascript and copy vendor javascript'
59
- task :coffeescript => (COMPILED_COFFEE + COPIED_JAVASCRIPTS)
32
+ task :coffeescript => :rake_deprecated do
33
+ Bwoken::CLI::Test.new({}).transpile
34
+ end
60
35
 
61
- CLEAN.include('integration/tmp/javascript')
62
- CLOBBER.include('integration/tmp')
36
+ desc 'remove any temporary products'
37
+ task :clean => :rake_deprecated do
38
+ Bwoken::CLI::Test.new({}).clean
39
+ end
63
40
 
41
+ desc 'remove any generated file'
42
+ task :clobber => :rake_deprecated do
43
+ Bwoken::CLI::Test.new({}).clobber
44
+ end
64
45
 
65
46
 
66
47
  desc 'Compile the workspace'
67
- task :compile do
68
- exit_status = Bwoken::Build.new.compile
69
- raise unless exit_status == 0
48
+ task :compile => :rake_deprecated do
49
+ opts = {:simulator => Bwoken::Device.should_use_simulator?}
50
+ Bwoken::CLI::Test.new(opts).compile
70
51
  end
71
52
 
72
53
 
@@ -75,29 +56,31 @@ device_families = %w(iphone ipad)
75
56
  device_families.each do |device_family|
76
57
 
77
58
  namespace device_family do
78
- task :test => [RESULTS_DIR, :coffeescript] do
79
- if ENV['RUN']
80
- Bwoken::Script.run_one ENV['RUN'], device_family
81
- else
82
- Bwoken::Script.run_all device_family
83
- end
59
+ task :test => [:rake_deprecated, RESULTS_DIR, :coffeescript] do
60
+ opts = {
61
+ :simulator => Bwoken::Device.should_use_simulator?,
62
+ :family => device_family
63
+ }
64
+ opts[:focus] = [ENV['RUN']] if ENV['RUN']
65
+
66
+ Bwoken::CLI::Test.new(opts).test
84
67
  end
85
68
  end
86
69
 
87
70
  desc "Run tests for #{device_family}"
88
- task device_family => "#{device_family}:test"
71
+ task device_family => [:rake_deprecated, "#{device_family}:test"]
89
72
 
90
73
  end
91
74
 
92
75
  desc 'Run all tests without compiling first'
93
- task :test do
94
- if ENV['FAMILY']
95
- Rake::Task[ENV['FAMILY']].invoke
96
- else
97
- device_families.each do |device_family|
98
- Rake::Task[device_family].invoke
99
- end
100
- end
76
+ task :test => :rake_deprecated do
77
+ opts = {
78
+ :simulator => Bwoken::Device.should_use_simulator?
79
+ }
80
+ opts[:focus] = [ENV['RUN']] if ENV['RUN']
81
+ opts[:family] = ENV['FAMILY'] if ENV['FAMILY']
82
+
83
+ Bwoken::CLI::Test.new(opts).test
101
84
  end
102
85
 
103
- task :default => [:compile, :test]
86
+ task :default => [:rake_deprecated, :compile, :test]
@@ -1,3 +1,3 @@
1
1
  module Bwoken
2
- VERSION = "1.3.0" unless defined?(::Bwoken::VERSION)
2
+ VERSION = "2.0.0.beta.1" unless defined?(::Bwoken::VERSION)
3
3
  end
data/lib/bwoken.rb CHANGED
@@ -1,15 +1,9 @@
1
1
  require 'fileutils'
2
2
 
3
- require 'bwoken/build'
4
- require 'bwoken/coffeescript'
5
- require 'bwoken/formatters/colorful_formatter'
6
- require 'bwoken/script'
7
- require 'bwoken/simulator'
8
- require 'bwoken/device'
9
- require 'bwoken/version'
10
-
11
3
  module Bwoken
12
4
  class << self
5
+ DEVICE_FAMILIES = %w(iphone ipad)
6
+
13
7
  def path
14
8
  File.join(project_path, 'integration')
15
9
  end
@@ -22,10 +16,6 @@ module Bwoken
22
16
  File.basename(File.basename(workspace_or_project, '.xcodeproj'), '.xcworkspace')
23
17
  end
24
18
 
25
- def formatter
26
- @formatter ||= Bwoken::ColorfulFormatter.new
27
- end
28
-
29
19
  def project_path
30
20
  Dir.pwd
31
21
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bwoken
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
5
- prerelease:
4
+ version: 2.0.0.beta.1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brad Grzesiak
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-10 00:00:00.000000000 Z
13
+ date: 2013-09-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: coffee-script-source
@@ -60,6 +60,22 @@ dependencies:
60
60
  - - ! '>='
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: json_pure
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
63
79
  - !ruby/object:Gem::Dependency
64
80
  name: rake
65
81
  requirement: !ruby/object:Gem::Requirement
@@ -76,6 +92,22 @@ dependencies:
76
92
  - - ! '>='
77
93
  - !ruby/object:Gem::Version
78
94
  version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: slop
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
79
111
  - !ruby/object:Gem::Dependency
80
112
  name: rspec
81
113
  requirement: !ruby/object:Gem::Requirement
@@ -114,22 +146,34 @@ email:
114
146
  - jaymes@bendyworks.com
115
147
  executables:
116
148
  - unix_instruments.sh
149
+ - bwoken
117
150
  extensions: []
118
151
  extra_rdoc_files: []
119
152
  files:
120
153
  - LICENSE
121
154
  - README.md
155
+ - bin/bwoken
122
156
  - bin/unix_instruments.sh
123
157
  - lib/bwoken/build.rb
158
+ - lib/bwoken/cli/init.rb
159
+ - lib/bwoken/cli/templates/integration/coffeescript/ipad/example.coffee
160
+ - lib/bwoken/cli/templates/integration/coffeescript/iphone/example.coffee
161
+ - lib/bwoken/cli/templates/integration/javascript/example_vendor.js
162
+ - lib/bwoken/cli/test.rb
163
+ - lib/bwoken/cli.rb
124
164
  - lib/bwoken/coffeescript/github_import_string.rb
125
165
  - lib/bwoken/coffeescript/import_string.rb
126
166
  - lib/bwoken/coffeescript.rb
127
167
  - lib/bwoken/configs/bwoken.xcconfig
128
168
  - lib/bwoken/device.rb
169
+ - lib/bwoken/device_runner.rb
129
170
  - lib/bwoken/formatter.rb
130
171
  - lib/bwoken/formatters/colorful_formatter.rb
172
+ - lib/bwoken/formatters/passthru_formatter.rb
131
173
  - lib/bwoken/script.rb
174
+ - lib/bwoken/script_runner.rb
132
175
  - lib/bwoken/simulator.rb
176
+ - lib/bwoken/simulator_runner.rb
133
177
  - lib/bwoken/tasks/bwoken.rake
134
178
  - lib/bwoken/tasks.rb
135
179
  - lib/bwoken/version.rb
@@ -148,16 +192,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
192
  version: '0'
149
193
  segments:
150
194
  - 0
151
- hash: -192482595553482221
195
+ hash: -2275845528582836031
152
196
  required_rubygems_version: !ruby/object:Gem::Requirement
153
197
  none: false
154
198
  requirements:
155
- - - ! '>='
199
+ - - ! '>'
156
200
  - !ruby/object:Gem::Version
157
- version: '0'
158
- segments:
159
- - 0
160
- hash: -192482595553482221
201
+ version: 1.3.1
161
202
  requirements: []
162
203
  rubyforge_project:
163
204
  rubygems_version: 1.8.25