eris 0.0.1

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.
Files changed (45) hide show
  1. data/.gitignore +6 -0
  2. data/.rspec +2 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +4 -0
  5. data/README.md +2 -0
  6. data/Rakefile +2 -0
  7. data/bin/eris +5 -0
  8. data/eris.gemspec +36 -0
  9. data/js_helpers/ErisHelpers.js +84 -0
  10. data/lib/eris.rb +22 -0
  11. data/lib/eris/eris.ru +3 -0
  12. data/lib/eris/lib/eris_config.rb +17 -0
  13. data/lib/eris/lib/jasmine_config_overrides.rb +43 -0
  14. data/lib/eris/lib/jasmine_rspec_runner.rb +34 -0
  15. data/lib/eris/lib/luna_request.rb +51 -0
  16. data/lib/eris/lib/proxied_request.rb +18 -0
  17. data/lib/eris/lib/server.rb +75 -0
  18. data/lib/eris/tasks/generate.rb +19 -0
  19. data/lib/eris/tasks/server.rb +14 -0
  20. data/lib/eris/templates/Gemfile +5 -0
  21. data/lib/eris/templates/Rakefile +32 -0
  22. data/lib/eris/templates/ci_build.sh +16 -0
  23. data/lib/eris/templates/eris_config.json +3 -0
  24. data/lib/eris/templates/jasmine.yml +77 -0
  25. data/lib/eris/templates/sampleSpec.js +13 -0
  26. data/lib/eris/templates/specHelper.js +3 -0
  27. data/lib/eris/version.rb +3 -0
  28. data/spec/fixtures/enyo/0.10/framework/enyo.js +1 -0
  29. data/spec/fixtures/sample_app/app/models/foo.js +1 -0
  30. data/spec/fixtures/sample_app/appinfo.json +10 -0
  31. data/spec/fixtures/sample_app/eris_config.json +3 -0
  32. data/spec/fixtures/sample_app/index.html.erb +20 -0
  33. data/spec/fixtures/sample_app/spec/acceptance/helpers/AppHelper.js +0 -0
  34. data/spec/fixtures/vcr_cassettes/failure.yml +34 -0
  35. data/spec/fixtures/vcr_cassettes/success.yml +62 -0
  36. data/spec/lib/eris/lib/eris_config_spec.rb +25 -0
  37. data/spec/lib/eris/lib/eris_spec.rb +7 -0
  38. data/spec/lib/eris/lib/luna_request_spec.rb +27 -0
  39. data/spec/lib/eris/lib/proxied_request_spec.rb +19 -0
  40. data/spec/lib/eris/lib/server_spec.rb +175 -0
  41. data/spec/lib/eris/tasks/generator_integration_spec.rb +38 -0
  42. data/spec/lib/eris/tasks/generator_spec.rb +90 -0
  43. data/spec/lib/eris/tasks/server_spec.rb +44 -0
  44. data/spec/spec_helper.rb +41 -0
  45. metadata +309 -0
@@ -0,0 +1,6 @@
1
+ .idea/
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
6
+ vendor/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format Fuubar
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-1.8.7-p174@eris --create
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in eris.gemspec
4
+ gemspec
@@ -0,0 +1,2 @@
1
+ Documentation Coming Soon
2
+ =========================
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/eris'
4
+
5
+ Eris::Tasks.start
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require File.dirname(__FILE__) + "/lib/eris/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "eris"
7
+ s.version = Eris::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["HP webOS", "Pivotal Labs"]
10
+ s.email = ["pair@pivotallabs.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Eris is a gem to help test driving webOS Enyo application development}
13
+ s.description = %q{}
14
+
15
+ s.rubyforge_project = "eris"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "rack"
23
+ s.add_dependency "json"
24
+ s.add_dependency "sinatra"
25
+ s.add_dependency "erubis"
26
+ s.add_dependency "thor"
27
+ s.add_dependency "curb"
28
+
29
+ s.add_development_dependency "rspec"
30
+ s.add_development_dependency "rack-test"
31
+ s.add_development_dependency "fuubar"
32
+ s.add_development_dependency "nokogiri"
33
+ s.add_development_dependency "vcr"
34
+ s.add_development_dependency "webmock"
35
+ s.add_development_dependency "rake"
36
+ end
@@ -0,0 +1,84 @@
1
+ // simulates an application relaunch
2
+ var relaunchWithParams = function(launchParams) {
3
+ // stubs for what Enyo expects when running in browser
4
+ window.PalmSystem = {
5
+ stageReady: function() {
6
+ },
7
+ setWindowOrientation: function() {
8
+ }
9
+ };
10
+
11
+ PalmSystem.launchParams = decodeURIComponent(launchParams);
12
+ Mojo.relaunch();
13
+ };
14
+
15
+ // Proxy all calls to palm:// and luna:// via novacom
16
+
17
+ var NovacomRequest = enyo.kind({
18
+ name: NovacomRequest,
19
+ kind: enyo.PalmService.Request,
20
+
21
+ call: function() {
22
+ var p = this.params || {};
23
+ console.log("==> CALLING AJAX <== " + JSON.stringify(p));
24
+
25
+ var lunaRequest = encodeURIComponent(enyo.json.stringify({
26
+ url: this.service + this.method,
27
+ body: p
28
+ }));
29
+
30
+ enyo.xhr.request({
31
+ url: '/luna?req=' + lunaRequest,
32
+ callback: enyo.hitch(this, "receive")
33
+ });
34
+ },
35
+
36
+ setResponse: function(a) {
37
+ console.error(a);
38
+ this.inherited(arguments);
39
+ },
40
+
41
+ createBridge: enyo.nop,
42
+ destroy: enyo.nop
43
+
44
+ });
45
+
46
+ if (!window.PalmSystem) {
47
+ enyo.PalmService.prototype.requestKind = "NovacomRequest";
48
+ enyo.DbService.prototype.requestKind = "NovacomRequest";
49
+ }
50
+ var logApiFailures = false;
51
+
52
+
53
+ // Proxy all XHRs to external APIs
54
+
55
+ var ProxiedRequest = enyo.kind({
56
+ name: ProxiedRequest,
57
+ kind: enyo.PalmService.Request,
58
+
59
+ call: function() {
60
+ var p = this.params || {};
61
+ console.log("==> PROXYING AJAX to " + this.url + " <== " + JSON.stringify(p));
62
+
63
+ var newRequest = encodeURIComponent(enyo.json.stringify({
64
+ url: this.url,
65
+ body: p
66
+ }));
67
+
68
+ enyo.xhr.request({
69
+ url: '/xhrproxy?req=' + newRequest,
70
+ callback: enyo.hitch(this, "receive")
71
+ });
72
+ },
73
+
74
+ setResponse: function(a) {
75
+ console.error(a);
76
+ this.inherited(arguments);
77
+ },
78
+
79
+ createBridge: enyo.nop,
80
+ destroy: enyo.nop
81
+ });
82
+
83
+ // For Test: inject test-only state before Enyo loads
84
+ window.development = true;
@@ -0,0 +1,22 @@
1
+ excluded_files = [
2
+ "/eris/lib/jasmine_config_overrides.rb",
3
+ "/eris/lib/jasmine_rspec_runner.rb"
4
+ ].map { |file| File.dirname(__FILE__) + file }
5
+
6
+ Dir[File.dirname(__FILE__) + "/eris/**/*.rb"].each do |file|
7
+ require file[0..-4] unless excluded_files.include?(file)
8
+ end
9
+
10
+ require 'thor'
11
+ require 'curb'
12
+ require 'pathname'
13
+
14
+ module Eris
15
+ class Tasks < Thor
16
+ include Thor::Actions
17
+ @@source_root = File.join(File.dirname(__FILE__), '..')
18
+ source_root File.join(File.dirname(__FILE__), '..')
19
+ end
20
+ end
21
+
22
+ Eris::FILE_PATH = File.expand_path(File.dirname(__FILE__))
@@ -0,0 +1,3 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'eris')
2
+
3
+ run Eris::Server
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+ require 'pathname'
3
+
4
+ class ErisConfig
5
+ def initialize(opts)
6
+ @config_hash = JSON.parse(File.read(opts[:config_path]))
7
+ @app_root = opts[:app_root]
8
+ end
9
+
10
+ def enyo_root
11
+ if Pathname.new(@config_hash['enyoRoot']).absolute?
12
+ @config_hash['enyoRoot']
13
+ else
14
+ File.join(@app_root, @config_hash['enyoRoot'])
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,43 @@
1
+ require 'eris/lib/eris_config'
2
+
3
+ module Jasmine
4
+ class Config
5
+ def src_files
6
+ if simple_config['src_files']
7
+ p match_files(src_dir, simple_config['src_files']) + ["usr/palm/frameworks/enyo/0.10/framework/enyo.js"]
8
+ match_files(src_dir, simple_config['src_files']) + ["usr/palm/frameworks/enyo/0.10/framework/enyo.js"]
9
+ else
10
+ []
11
+ end
12
+ end
13
+
14
+ def simple_config_file
15
+ File.join(project_root, 'spec/unit/support/jasmine.yml')
16
+ end
17
+ end
18
+ end
19
+
20
+ module Jasmine
21
+ def self.app(config)
22
+ Rack::Builder.app do
23
+ use Rack::Head
24
+
25
+ map('/run.html') { run Jasmine::Redirect.new('/') }
26
+ map('/__suite__') { run Jasmine::FocusedSuite.new(config) }
27
+
28
+ map('/__JASMINE_ROOT__') { run Rack::File.new(Jasmine.root) }
29
+ map(config.spec_path) { run Rack::File.new(config.spec_dir) }
30
+ map(config.root_path) { run Rack::File.new(config.project_root) }
31
+ eris_config = ErisConfig.new(:config_path => 'eris_config.json', :app_root => config.project_root)
32
+
33
+ map("/usr/palm/frameworks") { run Rack::File.new(eris_config.enyo_root) }
34
+
35
+ map('/') do
36
+ run Rack::Cascade.new([
37
+ Rack::URLMap.new('/' => Rack::File.new(config.src_dir)),
38
+ Jasmine::RunAdapter.new(config)
39
+ ])
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,34 @@
1
+ $:.unshift(ENV['JASMINE_GEM_PATH']) if ENV['JASMINE_GEM_PATH'] # for gem testing purposes
2
+
3
+ require 'rubygems'
4
+ require 'jasmine'
5
+ require 'eris/lib/jasmine_config_overrides'
6
+ if Jasmine::rspec2?
7
+ require 'rspec'
8
+ else
9
+ require 'spec'
10
+ end
11
+
12
+ jasmine_config = Jasmine::Config.new
13
+
14
+
15
+ spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
16
+
17
+ should_stop = false
18
+
19
+ if Jasmine::rspec2?
20
+ RSpec.configuration.after(:suite) do
21
+ spec_builder.stop if should_stop
22
+ end
23
+ else
24
+ Spec::Runner.configure do |config|
25
+ config.after(:suite) do
26
+ spec_builder.stop if should_stop
27
+ end
28
+ end
29
+ end
30
+
31
+
32
+ spec_builder.start
33
+ should_stop = true
34
+ spec_builder.declare_suites
@@ -0,0 +1,51 @@
1
+ require 'json'
2
+
3
+ module Eris
4
+ class LunaRequest
5
+
6
+ attr_reader :service
7
+
8
+ def initialize(options)
9
+ @service = options["url"]
10
+ @body = JSON.generate(options["body"])
11
+ end
12
+
13
+ def params
14
+ param_str = @body.dup
15
+ param_str.gsub!('\\n') { '\\\\\\n' } # Yes, this escapes NEWLINES (block form needed)
16
+ param_str.gsub!(' ', '\\ ') # escape spaces
17
+ param_str.gsub!(/'/) { %q('\\\\\'') } # escape single quotes (block form needed)
18
+ param_str
19
+ end
20
+
21
+ def url
22
+ "novacom run file://usr/bin/luna-send -- -n 1 -a com.palm.configurator -i #{@service} '#{params}'"
23
+ end
24
+
25
+ def execute
26
+ @luna_response = `#{url}`
27
+ # log_request
28
+ log_bad_json
29
+ @luna_response
30
+ end
31
+
32
+ def log_request
33
+ puts "\n\n====> BODY PARAMS <===="
34
+ pp @body
35
+ puts "\n\n====> NOVACOM REQUEST <===="
36
+ puts "Sending #{url}"
37
+ puts "\n\n====> NOVACOM RESPONSE <===="
38
+ puts @luna_response
39
+ end
40
+
41
+ def log_bad_json
42
+ begin
43
+ JSON.parse(@luna_response)
44
+ rescue
45
+ puts "BAD JSON FROM LUNA"
46
+ puts "Request: #{url}"
47
+ puts "Respose: #{@luna_response}"
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,18 @@
1
+ module Eris
2
+ class ProxiedRequest
3
+ def initialize(params)
4
+ @url = params["url"]
5
+ @body = params["body"]
6
+ end
7
+
8
+ def url
9
+ query_params = @body.collect {|k,v| "#{URI.encode(k.to_s)}=#{URI.encode(v.to_s)}" }.join('&')
10
+ "#{@url}?#{query_params}"
11
+ end
12
+
13
+ def execute
14
+ response = Curl::Easy.perform(url)
15
+ [response.body_str, response.response_code]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,75 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+ require 'erb'
4
+ require 'json'
5
+
6
+ module Eris
7
+ class Server < Sinatra::Base
8
+ JS_HELPER_PATH = File.dirname(__FILE__) + '/../../../js_helpers/'
9
+
10
+ def initialize(path=Dir.pwd)
11
+ @path = path
12
+ settings.views = path
13
+ super
14
+ end
15
+
16
+ Tilt.register :erb, Tilt[:erubis]
17
+ enable :raise_errors
18
+ disable :show_exceptions
19
+
20
+ ['/', '/index.html'].each do |route|
21
+ get route do
22
+ app_info = JSON.parse(File.read(File.join(@path, 'appinfo.json')))
23
+
24
+ locals = {
25
+ :app_title => app_info["title"],
26
+ :eris_helper_tags => '<script src="eris-helpers/ErisHelpers.js" type="text/javascript" eris-helpers=true></script>',
27
+ :app_helper_tag => nil,
28
+ :launch_params => params['launchParams']
29
+ }
30
+
31
+ app_helper = File.join('spec', 'acceptance', 'helpers', 'AppHelper.js')
32
+ if File.exist?(File.join(@path, app_helper))
33
+ locals[:app_helper_tag] = %Q{<script src="#{app_helper}" type="text/javascript" app-helper=true></script>}
34
+ end
35
+
36
+ erb :'index.html', :locals => locals
37
+ end
38
+ end
39
+
40
+ get '/luna*' do
41
+ req = JSON.parse(params[:req])
42
+ if req["url"] =~ /getCurrentPosition/
43
+ '{"altitude":-10000000,"errorCode":0,"heading":0,"horizAccuracy":-1,"latitude":37.392809,"longitude":-122.040461,"returnValue":true,"timestamp":1307557148000,"velocity":-1,"vertAccuracy":-1}'
44
+ else
45
+ LunaRequest.new(req).execute
46
+ end
47
+ end
48
+
49
+ get '/xhrproxy*' do
50
+ response, status_code = ProxiedRequest.new(JSON.parse(params[:req])).execute
51
+ status status_code
52
+ response
53
+ end
54
+
55
+ get '/eris-helpers/*' do
56
+ serve_static_files_from(JS_HELPER_PATH, params[:splat].first)
57
+ end
58
+
59
+ get '/usr/palm/frameworks/*' do
60
+ config = ErisConfig.new(:config_path => File.join(@path, 'eris_config.json'), :app_root => @path)
61
+ serve_static_files_from(config.enyo_root, params[:splat].first)
62
+ end
63
+
64
+ get '*' do
65
+ serve_static_files_from(@path, params[:splat].first)
66
+ end
67
+
68
+ def serve_static_files_from(path, filename)
69
+ path_to_static_file = File.expand_path(path + unescape(filename))
70
+
71
+ env['sinatra.static_file'] = path_to_static_file
72
+ send_file path_to_static_file, :disposition => nil
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,19 @@
1
+ require 'thor'
2
+
3
+ module Eris
4
+ class Tasks < Thor
5
+ desc "generate", "generate an enyo application"
6
+ def generate
7
+ template "lib/eris/templates/Gemfile",'Gemfile'
8
+ template "lib/eris/templates/Rakefile",'Rakefile'
9
+ template "lib/eris/templates/jasmine.yml", "spec/unit/support/jasmine.yml"
10
+ template "lib/eris/templates/sampleSpec.js", "spec/unit/source/sampleSpec.js"
11
+ create_file ".rvmrc", "rvm use ruby-1.9.2-p180@palm"
12
+ template "lib/eris/templates/ci_build.sh", "ci_build.sh"
13
+ chmod "ci_build.sh", 0755
14
+ template "lib/eris/templates/eris_config.json", "eris_config.json"
15
+ empty_directory "spec/unit/source/mock"
16
+ template "lib/eris/templates/specHelper.js", "spec/unit/specHelper.js"
17
+ end
18
+ end
19
+ end