diff --git a/Rakefile b/Rakefile index 6d1fa5c..5174f5f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,26 +1,23 @@ require 'rake/rdoctask' -desc "Run all specs by default" +TEST_CATEGORIES = [:remote, :interaction, :unit] + +desc "Run all unit specs by default" task :default => 'test:unit' namespace :test do - desc "Run all remote tests" - task :remote do - Dir[File.dirname(__FILE__) + '/test/remote/*_test.rb'].each do |file| - load file - end - end - - desc "Run all unit tests" - task :unit do - Dir[File.dirname(__FILE__) + '/test/unit/*_test.rb'].each do |file| - load file + TEST_CATEGORIES.each do |category| + desc "Run all #{category} tests" + task category do + Dir[File.dirname(__FILE__) + "/test/#{category}/*_test.rb"].each do |file| + load file + end end end end desc "Run all specs" -task :test => ['test:unit', 'test:remote'] +task :test => TEST_CATEGORIES.map { |category| "test:#{category}" } namespace :gem do desc "Build the gem" diff --git a/lib/broach/session.rb b/lib/broach/session.rb index f7bf95d..4ed5dd2 100644 --- a/lib/broach/session.rb +++ b/lib/broach/session.rb @@ -39,7 +39,7 @@ def credentials def get(path) response = REST.get(url_for(path), headers_for(:get), credentials) if response.ok? - return JSON.parse(response.body) + JSON.parse(response.body) else handle_response(:get, path, response) end @@ -48,9 +48,9 @@ def get(path) # Posts a resource to a certain path on the server. When the POST is successful # the parsed body is returned, otherwise an exception is raised. def post(path, payload) - response = REST.post(url_for(path), JSON.dump(payload), headers_for(:post), credentials) + response = REST.post(url_for(path), payload.to_json, headers_for(:post), credentials) if response.created? - return JSON.parse(response.body) + JSON.parse(response.body) else handle_response(:post, path, response) end diff --git a/test/interaction/active_support_test.rb b/test/interaction/active_support_test.rb new file mode 100644 index 0000000..d40796a --- /dev/null +++ b/test/interaction/active_support_test.rb @@ -0,0 +1,19 @@ +require File.expand_path('../../start', __FILE__) + +require 'open3' +require 'rbconfig' +module InteractionSpecHelpers + def ruby(script) + ruby_bin = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) + stdin, stdout, stderr = Open3.popen3("#{ruby_bin} #{script}") + stderr.read + end +end + +describe "Broach, when ActiveSupport is loaded" do + extend InteractionSpecHelpers + + it "should say hi in a room" do + ruby(File.expand_path('../scripts/say_hi.rb', __FILE__)).should == '' + end +end \ No newline at end of file diff --git a/test/interaction/scripts/say_hi.rb b/test/interaction/scripts/say_hi.rb new file mode 100644 index 0000000..420070f --- /dev/null +++ b/test/interaction/scripts/say_hi.rb @@ -0,0 +1,9 @@ +require 'rubygems' rescue nil +require 'active_support' +require 'rest' + +$:.unshift File.expand_path('../../../../lib', __FILE__) +require 'broach' + +Broach.settings = YAML.load_file(File.expand_path('../../../../settings.yml', __FILE__)) +Broach.speak(Broach.session.room, "Hi!") \ No newline at end of file