Class: SDKConnectionHarness
Class Attribute Summary collapse
-
.fixtures ⇒ Object
Returns the value of attribute fixtures.
-
.server_pid ⇒ Object
Returns the value of attribute server_pid.
Class Method Summary collapse
- .app_server ⇒ Object
- .configure_test_settings(overrides = {}) ⇒ Object
- .connect(overrides = {}) ⇒ Object
- .core_directory ⇒ Object
- .load_fixtures ⇒ Object
- .port ⇒ Object
- .running? ⇒ Boolean
- .start! ⇒ Object
- .stop! ⇒ Object
- .write_fixtures ⇒ Object
Class Attribute Details
.fixtures ⇒ Object
Returns the value of attribute fixtures.
11 12 13 |
# File 'lib/sdk_connection_harness.rb', line 11 def fixtures @fixtures end |
.server_pid ⇒ Object
Returns the value of attribute server_pid.
10 11 12 |
# File 'lib/sdk_connection_harness.rb', line 10 def server_pid @server_pid end |
Class Method Details
.app_server ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/sdk_connection_harness.rb', line 65 def app_server begin require 'thin' adapter = 'thin' rescue LoadError adapter = 'mongrel' end return "--adapter #{adapter}" end |
.configure_test_settings(overrides = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/sdk_connection_harness.rb', line 89 def configure_test_settings(overrides={}) Videojuicer.configure!({ :consumer_key => nil, :consumer_secret => nil, :api_version => 1, :protocol => "http", :host => "localhost", :port => port }.merge(overrides)) end |
.connect(overrides = {}) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/sdk_connection_harness.rb', line 79 def connect(overrides={}) fixtures = Mash.new(YAML.load(load_fixtures)).merge(overrides) configure_test_settings(fixtures) Videojuicer.enter_scope :seed_name => fixtures[:seed][:name], :consumer_key=>fixtures["write-master"][:consumer][:consumer_key], :consumer_secret=>fixtures["write-master"][:consumer][:consumer_secret], :token=>fixtures["write-master"][:authorized_token][:oauth_token], :token_secret=>fixtures["write-master"][:authorized_token][:oauth_token_secret] end |
.core_directory ⇒ Object
13 14 15 |
# File 'lib/sdk_connection_harness.rb', line 13 def core_directory File.(File.join(File.dirname(__FILE__), "..", "..", "vj-core")) end |
.load_fixtures ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/sdk_connection_harness.rb', line 50 def load_fixtures Dir.chdir(core_directory) do out = `./bin/rake videojuicer:sdk:setup MERB_ENV=test` out = out.match(/!!!([^!]+)!!!/m) self.fixtures = out[1] end end |
.port ⇒ Object
75 76 77 |
# File 'lib/sdk_connection_harness.rb', line 75 def port 6666 end |
.running? ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sdk_connection_harness.rb', line 35 def running? uri = URI.parse("http://localhost:#{port}/") req = Net::HTTP::Get.new(uri.path) begin resp = Net::HTTP.start(uri.host, uri.port) do |http| http.request(req) end return true rescue Exception => e # Connection refused means the daemon isn't running return false end end |
.start! ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sdk_connection_harness.rb', line 17 def start! stop! if running? puts "Starting vj-core from #{core_directory}\n" Thread.new do cur_dir = Dir.pwd Dir.chdir(core_directory) do `./bin/merb -d #{app_server} -p #{port} -e test --log ./log/sdk-development.log` end Dir.chdir(cur_dir) end end |
.stop! ⇒ Object
29 30 31 32 33 |
# File 'lib/sdk_connection_harness.rb', line 29 def stop! Thread.new do `killall -9 "merb : worker (port #{port})"` end end |
.write_fixtures ⇒ Object
58 59 60 61 62 63 |
# File 'lib/sdk_connection_harness.rb', line 58 def write_fixtures f = File.open(File.join(File.dirname(__FILE__), "..", "core-fixtures.yml"), "w+") f.rewind f.write(self.fixtures) f.close end |