fwtoolkit 0.3.4 → 0.4.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.
@@ -3,6 +3,8 @@ require 'rubygems'
3
3
  require 'xcodebuild'
4
4
  require 'cucumber/rake/task'
5
5
 
6
+ TEMPLATES_DIR = File.expand_path('../../../templates/', File.dirname(__FILE__))
7
+
6
8
  module XcodeBuild
7
9
  def self.run(args = "", output_buffer = STDOUT)
8
10
  command = "xcodebuild #{args} DSTROOT=/tmp/artifacts 2>&1"
@@ -28,8 +30,9 @@ end
28
30
  module FWToolkit
29
31
  module Tasks
30
32
  class BuildTask < ::Rake::TaskLib
33
+
31
34
  include Rake::DSL if defined?(Rake::DSL)
32
-
35
+
33
36
  attr_accessor :workspace
34
37
  attr_accessor :scheme
35
38
  attr_accessor :bundle_identifier
@@ -69,24 +72,44 @@ module FWToolkit
69
72
  sh command
70
73
  end
71
74
 
72
- desc 'Upload IPA to FWBuild'
75
+ task :validate_auth_token do
76
+ puts 'Please set FWBUILD_AUTH_TOKEN environment variable'
77
+ exit(-1) unless ENV['FWBUILD_AUTH_TOKEN']
78
+ end
79
+
73
80
  task :upload do
74
- auth_token=ENV['FWBUILD_AUTH_TOKEN']
81
+ auth_token = ENV['FWBUILD_AUTH_TOKEN']
75
82
  file_name = "#{scheme}.ipa"
76
83
  key = File.join('uploads', file_name)
77
84
  sh("curl -X POST -F 'key=#{key}' -F 'acl=bucket-owner-full-control' -F 'file=@/tmp/artifacts/Applications/#{scheme}.ipa' https://fw.fwbuild.production.s3.amazonaws.com/ --progress-bar")
78
- sh("curl 'http://fwbuild.futureworkshops.com/apps/builds.json?bundle_identifier=#{@bundle_identifier}&s3_upload_name=#{file_name}&auth_token=#{auth_token}'")
85
+ sh("curl 'http://fwbuild.futureworkshops.com/apps/builds.json?bundle_identifier=#{@bundle_identifier}&s3_upload_name=#{file_name}&auth_token=#{auth_token}&build[version]=#{DateTime.now.to_s}'")
79
86
  end
80
87
 
81
88
  desc 'Build and Upload IPA'
82
- task :build_upload => ['release_iphoneos:archive', :ipa, :upload]
89
+ task :build_upload => [:validate_auth_token, 'release_iphoneos:archive', :ipa, :upload]
83
90
  end
84
91
 
85
92
  namespace :frank do
86
-
87
93
  desc 'Setup Frank'
88
94
  task :setup do
89
- sh "frank setup"
95
+ sh 'frank setup'
96
+
97
+ test_dir = File.join(TEMPLATES_DIR, 'cucumber')
98
+ features_dir = File.join('Frank', 'features')
99
+ support_dir = File.join(features_dir, 'support')
100
+ steps_dir = File.join(features_dir, 'step_definitions')
101
+ views_dir = File.join(support_dir, 'views')
102
+
103
+ remove_file(File.join(features_dir, 'my_first.feature'))
104
+ cp(File.join(test_dir, 'env.rb'), support_dir)
105
+ cp(File.join(test_dir, 'mimic.rb'), support_dir)
106
+ mkdir(views_dir)
107
+ cp(File.join(test_dir, 'my_objects_json.erb'), views_dir)
108
+ cp(File.join(test_dir, 'my_objects_xml.erb'), views_dir)
109
+ cp(File.join(test_dir, 'launch_steps.rb'), steps_dir)
110
+ cp(File.join(test_dir, 'example.feature'), features_dir)
111
+ cp(File.join(test_dir, 'AppDelegate+Frank.h'), './')
112
+ cp(File.join(test_dir, 'AppDelegate+Frank.m'), './')
90
113
  end
91
114
 
92
115
  desc 'Build the frankified App'
@@ -2,6 +2,49 @@ require 'pickle'
2
2
 
3
3
  module FWToolkit
4
4
  module Test
5
+ class FrankCache
6
+ @@klass_to_objects = {}
7
+ @@id_to_object = {}
8
+
9
+ def self.add_object(object)
10
+ object.id = object.object_id
11
+
12
+ # add to id to object hash
13
+ @@id_to_object[object.object_id.to_s] = object
14
+
15
+ # add to klass to object hash
16
+ @@klass_to_objects[object.class.name] = [] unless @@klass_to_objects[object.class.name]
17
+ @@klass_to_objects[object.class.name] << object
18
+ end
19
+
20
+ def self.all_objects(klass)
21
+ @@klass_to_objects[klass.name] ? @@klass_to_objects[klass.name] : []
22
+ end
23
+
24
+ def self.find(id)
25
+ @@id_to_object[id.to_s]
26
+ end
27
+
28
+ def self.find_first(klass, conditions)
29
+ self.find_all(klass, conditions).first
30
+ end
31
+
32
+ def self.find_all(klass, conditions)
33
+ objects = []
34
+ FWToolkit::Test::FrankCache.all_objects(klass).each do |o|
35
+ match = true
36
+ conditions.keys.each do |k|
37
+ if not eval("o.#{k}").eql? conditions[k]
38
+ match = false
39
+ break
40
+ end
41
+ end
42
+ objects << o if match
43
+ end
44
+ objects
45
+ end
46
+ end
47
+
5
48
  class FrankModel
6
49
 
7
50
  attr_accessor :id, :core_data_entity
@@ -12,33 +55,26 @@ module FWToolkit
12
55
  # Gets a list of the available models for this adapter
13
56
  def self.model_classes
14
57
  klasses = ::FWToolkit::Test::FrankModel.__send__(:descendants)
15
-
16
- #klasses.select do |klass|
17
- # !klass.abstract_class? && klass.table_exists? && !except_classes.include?(klass.name)
18
- #end
19
58
  end
20
59
 
21
60
  # get a list of column names for a given class
22
61
  def self.column_names(klass)
23
- #klass.column_names
24
- []
62
+ klass.new.methods
25
63
  end
26
64
 
27
65
  # Get an instance by id of the model
28
66
  def self.get_model(klass, id)
29
- FWToolkit::Test::FrankModel.object_in_cache(id)
67
+ FWToolkit::Test::FrankCache.find(id)
30
68
  end
31
69
 
32
70
  # Find the first instance matching conditions
33
71
  def self.find_first_model(klass, conditions)
34
- #klass.find(:first, :conditions => conditions)
35
- puts "find_first_model"
72
+ FWToolkit::Test::FrankCache.find_first(klass, conditions)
36
73
  end
37
74
 
38
75
  # Find all models matching conditions
39
76
  def self.find_all_models(klass, conditions)
40
- #klass.find(:all, :conditions => conditions)
41
- puts "find_all_models"
77
+ FWToolkit::Test::FrankCache.find_all(klass, conditions)
42
78
  end
43
79
 
44
80
  # Create a model using attributes
@@ -47,15 +83,28 @@ module FWToolkit
47
83
  end
48
84
  end
49
85
 
50
- @@object_cache = {}
51
-
52
86
  def self.object_in_cache(id)
53
- return @@object_cache[id.to_s]
87
+ FWToolkit::Test::FrankCache.find(id)
88
+ end
89
+
90
+ def self.all_objects
91
+ FWToolkit::Test::FrankCache.all_objects(self)
54
92
  end
55
93
 
56
94
  def save!
57
- self.id = self.object_id
58
- @@object_cache[self.object_id.to_s] = self
95
+ FWToolkit::Test::FrankCache.add_object(self)
96
+ end
97
+
98
+ def self.find(id)
99
+ FWToolkit::Test::FrankCache.find(id)
100
+ end
101
+
102
+ def self.find_first(conditions={})
103
+ FWToolkit::Test::FrankCache.find_first(self, conditions)
104
+ end
105
+
106
+ def self.find_all(conditions={})
107
+ FWToolkit::Test::FrankCache.find_all(self, conditions)
59
108
  end
60
109
  end
61
110
  end
@@ -1,26 +1,11 @@
1
- require 'mimic'
2
- require 'socket'
3
- require 'net/http'
4
1
  require 'json'
5
- require 'erb'
6
2
  require 'frank-cucumber/gateway'
7
- require 'pickle/world'
8
3
  require 'cfpropertylist'
9
4
 
10
5
  module FWToolkit
11
6
  module Test
12
7
  module ModelHelpers
13
8
 
14
- def mimic_server(port=11988)
15
- @mimic = Mimic.mimic(:port => port) unless @mimic
16
- @mimic
17
- end
18
-
19
- # todo: remove default response_content_type
20
- def queue_mimic_get_response(path, content, response_content_type = 'application/xml')
21
- mimic_server.get(path).returning(content, 200, {'Content-Type' => response_content_type})
22
- end
23
-
24
9
  def fwt_app_exec(method_name, *method_args)
25
10
  operation_map = Frank::Cucumber::Gateway.build_operation_map(method_name,method_args)
26
11
 
@@ -31,53 +16,6 @@ module FWToolkit
31
16
 
32
17
  return Frank::Cucumber::Gateway.evaluate_frankly_response( res, "app_exec #{method_name}" )
33
18
  end
34
-
35
- def fwt_template_response(template_file_name, capture_models = [], options = nil)
36
-
37
- # probably should put some asserts in here
38
- # template_file_name should be single if capture_models.count == 0
39
- # template_file_name should be plural if capture_models.count > 0
40
- unless capture_models.empty?
41
- factory, name_or_index = *parse_model(capture_models[0])
42
- unless template_file_name
43
- template_file_name = factory.pluralize
44
- end
45
-
46
- objects = []
47
- capture_models.each do |capture_model|
48
- objects << model!(capture_model)
49
- end
50
-
51
- eval("@#{factory.pluralize} = objects")
52
- eval("@#{factory} = objects.first")
53
- end
54
-
55
- if options
56
- options.each do |option|
57
- key, value = option.split(":")
58
- eval("@#{key} = value")
59
- end
60
- end
61
-
62
- template_file = File.join(Dir.pwd, 'Frank', 'features', 'support', 'templates', "#{template_file_name}.erb")
63
- erb = ERB.new(File.open(template_file).read, 0,"")
64
- result = erb.result(binding)
65
-
66
- # cleanup
67
- unless capture_models.empty?
68
- eval("@#{factory.pluralize} = nil")
69
- eval("@#{factory} = nil")
70
- end
71
-
72
- if options
73
- options.each do |option|
74
- key, value = option.split(":")
75
- eval("@#{key} = nil")
76
- end
77
- end
78
-
79
- result
80
- end
81
19
 
82
20
  def fwt_simulator_applications_dir
83
21
  File.join(Dir.home, 'Library', 'Application Support', 'iPhone Simulator', fwt_ios_sdk, 'Applications')
@@ -130,12 +68,4 @@ module FWToolkit
130
68
  end
131
69
  end
132
70
  end
133
- World(FWToolkit::Test::ModelHelpers)
134
-
135
- Before do |scenario|
136
- fwt_simulator_reset_data(fwt_ios_sdk)
137
- end
138
-
139
- After do |scenario|
140
- Mimic.cleanup!
141
- end
71
+ World(FWToolkit::Test::ModelHelpers)
@@ -1,3 +1,3 @@
1
1
  module FWToolkit
2
- VERSION = "0.3.4"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -0,0 +1,15 @@
1
+ //
2
+ // AppDelegate+Frank.h
3
+ // FWToolkit
4
+ //
5
+ // Created by Matt Brooke-Smith on 14/10/2012.
6
+ // Copyright (c) 2012 Future Workshops. All rights reserved.
7
+ //
8
+
9
+ #import "AppDelegate.h"
10
+
11
+ @interface AppDelegate (Frank)
12
+
13
+ - (void) seedCoreData:(NSString *)json;
14
+
15
+ @end
@@ -0,0 +1,41 @@
1
+ //
2
+ // AppDelegate+Frank.m
3
+ // QlikView
4
+ //
5
+ // Created by Matt Brooke-Smith on 18/07/2012.
6
+ // Copyright (c) 2012 Future Workshops. All rights reserved.
7
+ //
8
+
9
+ #import "AppDelegate+Frank.h"
10
+ #import <CoreData/CoreData.h>
11
+ #import <JSONKit/JSONKit.h>
12
+ #import <RestKit/RestKit.h>
13
+ #import "RKObjectManager+QVWOfflineTests.h"
14
+
15
+ @implementation AppDelegate (Frank)
16
+
17
+ - (void) seedCoreData:(NSString *)json
18
+ {
19
+ NSArray *objectsArray = [json objectFromJSONString];
20
+ NSManagedObjectContext *managedObjectContext = [[RKObjectManager sharedManager].objectStore managedObjectContextForCurrentThread];
21
+ for (NSDictionary *objectDictionary in objectsArray) {
22
+ NSString *entityName = [objectDictionary allKeys][0];
23
+ NSDictionary *dictionary = [objectDictionary objectForKey:entityName];
24
+ NSManagedObject *object = [NSEntityDescription insertNewObjectForEntityForName:entityName inManagedObjectContext:managedObjectContext];
25
+ for (NSString *nextKey in [dictionary allKeys]) {
26
+ if ([object respondsToSelector:NSSelectorFromString(nextKey)]) {
27
+ NSObject *value = [dictionary objectForKey:nextKey];
28
+ if (value != [NSNull null]) {
29
+ [object setValue:value forKey:nextKey];
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ NSError *error = nil;
36
+ if (![managedObjectContext save:&error]) {
37
+ WLog(@"Error saving: %@", [error localizedDescription]);
38
+ }
39
+ }
40
+
41
+ @end
@@ -0,0 +1,19 @@
1
+ require 'fwtoolkit'
2
+ require 'frank-cucumber'
3
+
4
+ Frank::Cucumber::FrankHelper.use_shelley_from_now_on
5
+
6
+ APP_BUNDLE_PATH = File.expand_path( '../../../frankified_build/Frankified.app', __FILE__ )
7
+
8
+ IOS_SDK_VERSION = '6.0'
9
+ #XCODE_VERSION = '4.5.1' # not currently used - look out for this in FWToolkit 0.5
10
+
11
+ AfterConfiguration do
12
+ require 'pickle/world'
13
+ require 'fwtoolkit/test/pickle_steps'
14
+ require 'fwtoolkit/test/ui_steps'
15
+ end
16
+
17
+ After do |scenario|
18
+ Mimic.cleanup!
19
+ end
@@ -0,0 +1,7 @@
1
+ Feature:
2
+ As an # Actor in the system
3
+ I want to # perform a task
4
+ In order to # achieve something
5
+
6
+ Scenario: Open the App
7
+ Given I launch the app in the iphone simulator
@@ -0,0 +1,29 @@
1
+ require 'pickle/world'
2
+
3
+ def ios_sdk_version
4
+ IOS_SDK_VERSION
5
+ end
6
+
7
+ def xcode_version
8
+ XCODE_VERSION
9
+ end
10
+
11
+ def app_path
12
+ ENV['APP_BUNDLE_PATH'] || (defined?(APP_BUNDLE_PATH) && APP_BUNDLE_PATH)
13
+ end
14
+
15
+ Given /^I launch the app in the (iphone|ipad) simulator$/ do |device|
16
+ launch_app app_path, ios_sdk_version, device
17
+ end
18
+
19
+ Given /^I reset and launch the app in the (iphone|ipad) simulator$/ do |device|
20
+ fwt_simulator_reset_data ios_sdk_version
21
+ launch_app app_path, ios_sdk_version, device
22
+ end
23
+
24
+ Given /^I reset and launch the app in the (iphone|ipad) simulator, seeded with #{capture_model}$/ do |device, capture_model|
25
+ fwt_simulator_reset_data ios_sdk_version
26
+ launch_app app_path, ios_sdk_version, device
27
+ fwt_seed_app [capture_model]
28
+ launch_app app_path, ios_sdk_version, device
29
+ end
@@ -0,0 +1,93 @@
1
+ require 'mimic'
2
+
3
+ # Listen on the following :port
4
+ # Add the following to your objective-c code, in the place where your
5
+ # server root is configured
6
+ # #ifdef FRANIFIFIED
7
+ # server = "http://localhost:11988"
8
+ # #else
9
+ # server = <your production server>
10
+ # #endif
11
+ Mimic.mimic(:port => 11988) do |m|
12
+
13
+ # use the 'views' directory adjacent to this file for API templates
14
+ set :views, File.expand_path('views', File.dirname(__FILE__))
15
+
16
+ # EXAMPLE ROUTE 1 - XML summary using erb template
17
+ # Uncomment to get xml defined by 'views/my_objects_xml.erb' containing all MyObject instances
18
+ # @see views/my_objects_xml.erb
19
+ #
20
+ # get '/my_objects.xml' do
21
+ # @my_objects = MyObject.find_all
22
+ # erb :my_objects_xml, :content_type => 'application/xml'
23
+ # end
24
+
25
+ # EXAMPLE ROUTE 2 - JSON summary using erb template
26
+ # Uncomment to get json defined by 'views/my_objects_json.erb' containing all MyObject instances
27
+ # @see views/my_objects_json.erb
28
+ #
29
+ # get '/my_objects.json' do
30
+ # @my_objects = MyObject.find_all
31
+ # erb :my_objects_json, :content_type => 'application/json'
32
+ # end
33
+
34
+ # EXAMPLE ROUTE 3 - JSON detail using erb template
35
+ # Uncomment to get json defined by 'views/my_object_json.erb' containing detail about a single MyObject instance
36
+ # found using the URL parameter "name", i.e. /myobject.json?name=Fred
37
+ #
38
+ # get '/my_object.json' do
39
+ # @my_objects = MyObject.find_first({:name => params[:name]})
40
+ # erb :my_object_json, :content_type => 'application/json'
41
+ # end
42
+
43
+ # EXAMPLE ROUTE 4 - JSON summary using JBuilder
44
+ # Uncomment to get json defined programatically.
45
+ # This is recommended if you are building from scratch or testing a system which has concise, well defined JSON,
46
+ # as this will be more maintainable than erb templates
47
+ # You will also need to add
48
+ # gem 'jbuilder'
49
+ # to your Gemfile
50
+ # See more on JBuilder here https://github.com/rails/jbuilder
51
+ #
52
+ # get '/my_objects.json' do
53
+ # my_objects = MyObject.find_all
54
+ # json = Jbuilder.encode do |json|
55
+ # json.array!(my_objects) do |o|
56
+ # json.name o.name
57
+ # end
58
+ # end
59
+ # [200, {'Content-Type' => 'application/json'}, json]
60
+ # end
61
+
62
+ # EXAMPLE ROUTE 5 - Authentication
63
+ # An example route requiring authentication, and setting a cookie once the user 'admin', 'password' authorized
64
+ # def protected!
65
+ # unless authorized?
66
+ # response['WWW-Authenticate'] = %(Basic realm="Restricted Area")
67
+ # throw(:halt, [401, "Not authorized\n"])
68
+ # end
69
+ # end
70
+ #
71
+ # def authorized?
72
+ # if request.cookies.key?('my cookie')
73
+ # true
74
+ # else
75
+ # @auth ||= Rack::Auth::Basic::Request.new(request.env)
76
+ # if(@auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['admin', 'password'])
77
+ # response.set_cookie('my cookie', :value => {:user => 'admin@admin.com'}, :expires => Time.now + 10.minutes, :path => "/")
78
+ # true
79
+ # else
80
+ # false
81
+ # end
82
+ # end
83
+ # end
84
+ #
85
+ # get '/my_secret_objects.xml' do
86
+ # protected!
87
+ # @my_objects = MyObject.find_all({:name => 'secret'})
88
+ # erb :my_objects_json, :content_type => 'application/json'
89
+ # end
90
+
91
+
92
+
93
+ end
@@ -0,0 +1,7 @@
1
+ [
2
+ <%- @my_objects.each do |o| %>
3
+ {
4
+ "name": "<%= o.name %>"
5
+ },
6
+ <% end %>
7
+ ]
@@ -0,0 +1,7 @@
1
+ <my_objects>
2
+ <%- @my_objects.each do |t| %>
3
+ <my_object>
4
+ <name><%= t.name %></name>
5
+ <my_object>
6
+ <% end %>
7
+ </my_objects>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fwtoolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-08 00:00:00.000000000 Z
12
+ date: 2012-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber
@@ -162,7 +162,7 @@ dependencies:
162
162
  requirements:
163
163
  - - '='
164
164
  - !ruby/object:Gem::Version
165
- version: 1.1.1
165
+ version: 0.9.5
166
166
  type: :runtime
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
@@ -170,7 +170,7 @@ dependencies:
170
170
  requirements:
171
171
  - - '='
172
172
  - !ruby/object:Gem::Version
173
- version: 1.1.1
173
+ version: 0.9.5
174
174
  - !ruby/object:Gem::Dependency
175
175
  name: CFPropertyList
176
176
  requirement: !ruby/object:Gem::Requirement
@@ -218,12 +218,19 @@ files:
218
218
  - lib/fwtoolkit/test/frank_model.rb
219
219
  - lib/fwtoolkit/test/misc_steps.rb
220
220
  - lib/fwtoolkit/test/model_helper.rb
221
- - lib/fwtoolkit/test/model_steps.rb
222
221
  - lib/fwtoolkit/test/network_steps.rb
223
222
  - lib/fwtoolkit/test/pickle_steps.rb
224
223
  - lib/fwtoolkit/test/ui_helper.rb
225
224
  - lib/fwtoolkit/test/ui_steps.rb
226
225
  - lib/fwtoolkit/version.rb
226
+ - templates/cucumber/AppDelegate+Frank.h
227
+ - templates/cucumber/AppDelegate+Frank.m
228
+ - templates/cucumber/env.rb
229
+ - templates/cucumber/example.feature
230
+ - templates/cucumber/launch_steps.rb
231
+ - templates/cucumber/mimic.rb
232
+ - templates/cucumber/my_objects_json.erb
233
+ - templates/cucumber/my_objects_xml.erb
227
234
  - templates/models/factories.rb.erb
228
235
  - templates/models/model.rb.erb
229
236
  homepage: ''
@@ -1,19 +0,0 @@
1
- # This file is generated by FWToolkit and is covered by the license at
2
- #
3
- require 'fwtoolkit/test/model_helper.rb'
4
-
5
- Given /^the server responds with(?: "([^\"]*)" for)? path "([^\"]*)" 0 ([^"]*)$/ do |template_file_name, path, variable_name|
6
- eval("@#{variable_name} = []")
7
- content = fwt_template_response(template_file_name != nil ? template_file_name : variable_name)
8
- queue_mimic_get_response(path, content)
9
- end
10
-
11
- Given /^the server responds with "([^\"]*)" for path "([^\"]*)" with #{capture_model}(?: with #{capture_fields})?$/ do |template_file_name, path, capture_model, options|
12
- content = fwt_template_response(template_file_name, [capture_model], options)
13
- queue_mimic_get_response(path, content)
14
- end
15
-
16
- Given /^the server responds with "([^\"]*)" for path "([^\"]*)" with #{capture_model} and #{capture_model}(?: with #{capture_fields})?$/ do |template_file_name, path, capture_model_1, capture_model_2, options|
17
- content = fwt_template_response(template_file_name, [capture_model_1, capture_model_2], options)
18
- queue_mimic_get_response(path, content)
19
- end