Skip to content

Commit

Permalink
update test suite so that it passes
Browse files Browse the repository at this point in the history
update rspec syntax to remove deprecation warnings

Conflicts:
	Gemfile
	Rakefile
	spec/spec_helper.rb
	spec/support/custom_matchers.rb
	spec/wrest/components/translators/json_spec.rb
	spec/wrest/curl/response_spec.rb
	spec/wrest/http/response_spec.rb
	spec/wrest/http_codes_spec.rb
	spec/wrest/native/redirection_spec.rb
	spec/wrest/native/request_spec.rb
	spec/wrest/native/response_spec.rb
	spec/wrest/uri_spec.rb
  • Loading branch information
Jeremy Shearer authored and birkirb committed Oct 29, 2013
1 parent 962f5bc commit 0a78782
Show file tree
Hide file tree
Showing 19 changed files with 143 additions and 143 deletions.
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ group :libcurl_support do
end

group :nokogiri do
gem 'nokogiri', '~> 1'
gem 'nokogiri'
end

group :libxml do
platforms :ruby do
gem 'libxml-ruby', '~> 2' unless Object.const_defined?('RUBY_ENGINE') && RUBY_ENGINE =~ /rbx/
gem 'libxml-ruby' unless Object.const_defined?('RUBY_ENGINE') && RUBY_ENGINE =~ /rbx/
end
end

group :jrexml do
platforms :jruby do
gem 'jrexml', '~> 0.5.3'
Expand Down
14 changes: 7 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace :rspec do
ENV["wrest_functional_spec"] = "true"
Rake::Task["rspec:spec_runner"].invoke
end

RSpec::Core::RakeTask.new(:spec_runner) do |task|
task.pattern = 'spec/wrest/**/*_spec.rb'
end
Expand Down Expand Up @@ -91,7 +91,7 @@ namespace (:benchmark) do

class Ooga < Wrest::Resource::Base
end
class Booga < ActiveResource::Base
class Booga < ActiveResource::Base
self.site=''
end
end
Expand Down Expand Up @@ -217,8 +217,8 @@ namespace (:benchmark) do
}
end
end
end
end

desc "Benchmark keepalive connections (needs functional/sample_rails_app running with class-caching on and keep-alive enabled)"
task :keep_alive => :setup_test_classes do
n = 20
Expand All @@ -230,7 +230,7 @@ namespace (:benchmark) do
'http://localhost:3000/lead_bottles.xml?owner=Kai&type=bottle'.to_uri.get
}
end

rpt.report("Keep-alive connection (Connection: Keep-Alive)") do
Wrest::Native::Session.new('http://localhost:3000'.to_uri) do |session|
n.times {
Expand All @@ -246,7 +246,7 @@ namespace (:benchmark) do
task :deserialise_xml => :setup_test_classes do |t|
n = 100
puts "Deserialising using #{ActiveSupport::XmlMini.backend}"

Benchmark.bmbm(10) do |rpt|
rpt.report("Hash.from_xml") do
n.times {
Expand All @@ -255,7 +255,7 @@ namespace (:benchmark) do
end
end
end

def serialised_data
<<-EOXML
<?xml version="1.0" encoding="UTF-8"?>
Expand Down
20 changes: 10 additions & 10 deletions examples/facebook_auth/spec/lib/models/facebook_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@
params["redirect_uri"].should == "http://redirect_uri"
params["client_id"].should_not be_nil
end

it "should exchange authentication code for the access token" do
uri_string = "http://graph.facebook.com"

FacebookClient::Config.should_receive(:[]).with("client_id").and_return("id")
FacebookClient::Config.should_receive(:[]).with("client_secret").and_return("secret")
FacebookClient::Config.should_receive(:[]).with("facebook_uri").and_return(uri_string)
facebook_uri = mock(Wrest::Uri)
access_token_uri = mock(Wrest::Uri)

facebook_uri = double(Wrest::Uri)
access_token_uri = double(Wrest::Uri)
uri_string.should_receive(:to_uri).and_return(facebook_uri)
facebook_uri.should_receive(:[]).with('/oauth/access_token').and_return(access_token_uri)
response = mock("Response", :body => 'access_token=access_token')
response = double("Response", :body => 'access_token=access_token')
request_params = {:client_id => "id", :redirect_uri => "http://redirect_uri",
:client_secret => "secret", :code => "auth_code"}
access_token_uri.should_receive(:post_form).with(request_params).and_return(response)
client.acquire_access_token("http://redirect_uri","auth_code").should == "access_token"
end

context "authorized access" do
it "should get a resource at the given path using access token" do
uri_string = "http://graph.facebook.com"
FacebookClient::Config.should_receive(:[]).with("facebook_uri").and_return(uri_string)
facebook_uri = mock(Wrest::Uri)
get_uri = mock(Wrest::Uri)
facebook_uri = double(Wrest::Uri)
get_uri = double(Wrest::Uri)
uri_string.should_receive(:to_uri).and_return(facebook_uri)
facebook_uri.should_receive(:[]).with('/me').and_return(get_uri)
response = mock("Response", :body => 'body')
response = double("Response", :body => 'body')
get_uri.should_receive(:get).with(:access_token => "access_token").and_return(response)
client.authorized_get("/me", "access_token").body.should == 'body'
end
Expand Down
8 changes: 4 additions & 4 deletions examples/facebook_auth/spec/lib/models/facebook_user_spec.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
require 'spec_helper'

describe FacebookUser do

context "authenticated" do
it "should not be authenticated if access token is not available" do
user = FacebookUser.new("")
user.should_not be_authenticated
end

it "should be authenticate if access token is available" do
user = FacebookUser.new("access_token")
user.should be_authenticated
end
end

it "should fetch profile using access token" do
user = FacebookUser.new("access_token")
client = FacebookClient.new
FacebookClient.should_receive(:new).and_return(client)
response = mock("Response", :deserialise => {:name => "Booga"})
response = double("Response", :deserialise => {:name => "Booga"})
client.should_receive(:authorized_get).with("/me", "access_token").and_return(response)
profile = user.profile
profile.name.should == "Booga"
Expand Down
2 changes: 1 addition & 1 deletion lib/wrest/test/request_patches.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Wrest::Native::Request
def invoke
raise Wrest::Exceptions::RealRequestMadeInTestEnvironmet, 'A real HTTP request was made while running tests. Please avoid using live HTTP connections while testing and replace them with mocks.'
raise Wrest::Exceptions::RealRequestMadeInTestEnvironmet, 'A real HTTP request was made while running tests. Please avoid using live HTTP connections while testing and replace them with doubles.'
end
end
10 changes: 5 additions & 5 deletions spec/wrest/cache_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
# 304 is Not Modified
it "should use the cached response if the server returns 304" do
not_modified_response = @ok_response.clone
not_modified_response.should_receive(:code).any_number_of_times.and_return('304')
not_modified_response.stub(:code).and_return('304')
@cache.should_receive(:[]).with(@get.hash).and_return(@cached_response)

@cache_proxy.should_receive(:send_validation_request_for).and_return(not_modified_response)
Expand All @@ -143,7 +143,7 @@
it "should call update_cache_headers" do

not_modified_response = @ok_response.clone
not_modified_response.should_receive(:code).any_number_of_times.and_return('304')
not_modified_response.stub(:code).and_return('304')
@cache.should_receive(:[]).with(@get.hash).and_return(@cached_response)

@cache_proxy.should_receive(:send_validation_request_for).and_return(not_modified_response)
Expand Down Expand Up @@ -178,10 +178,10 @@
end
end
end

it "should use it if the server returns a new response" do
new_response = Wrest::Native::Response.new(build_ok_response('', cacheable_headers()))
new_response.should_receive(:code).any_number_of_times.and_return('200')
new_response.stub(:code).and_return('200')

@cache.should_receive(:[]).with(@get.hash).and_return(@cached_response)
@cache_proxy.should_receive(:send_validation_request_for).and_return(new_response)
Expand All @@ -191,7 +191,7 @@

it "should also cache it when the server returns a new response" do
new_response = Wrest::Native::Response.new(build_ok_response('', cacheable_headers()))
new_response.should_receive(:code).any_number_of_times.and_return('200')
new_response.stub(:code).and_return('200')

@cache.should_receive(:[]).with(@get.hash).and_return(@cached_response)
@cache_proxy.should_receive(:send_validation_request_for).and_return(new_response)
Expand Down
2 changes: 1 addition & 1 deletion spec/wrest/components/container/alias_accessors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Wrest::Components
end

it "should provide a macro to enable aliasing accessors" do
lambda{ @Demon.class_eval{ alias_accessors :shiriki => :chambala } }.should_not raise_error(NoMethodError)
lambda{ @Demon.class_eval{ alias_accessors :shiriki => :chambala } }.should_not raise_error()
end

describe 'aliasing' do
Expand Down
2 changes: 1 addition & 1 deletion spec/wrest/components/mutators/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module Wrest::Components
}]]
).should == ["result", {"publish_date" => "1240326000", "news_source" => {"online"=>"PC via News", "unique_id"=>1}}]
end

it "should register all subclasses in the registry" do
class SomeMutator < Mutators::Base; end
Mutators::REGISTRY[:some_mutator].should == SomeMutator
Expand Down
26 changes: 13 additions & 13 deletions spec/wrest/components/translators/json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@
module Wrest::Components::Translators
describe Json do
let(:http_response) { double('Http Reponse') }

it "should know how to convert json to a hashmap" do
http_response.should_receive(:body).and_return("{
\"menu\": \"File\",
\"commands\": [
http_response.should_receive(:body).and_return("{
\"menu\": \"File\",
\"commands\": [
{
\"title\": \"New\",
\"title\": \"New\",
\"action\":\"CreateDoc\"
},
},
{
\"title\": \"Open\",
\"title\": \"Open\",
\"action\": \"OpenDoc\"
},
},
{
\"title\": \"Close\",
\"action\": \"CloseDoc\"
}
]
]
}")

result = { "commands"=>[{"title"=>"New", "action"=>"CreateDoc"},
{"title"=>"Open","action"=>"OpenDoc"},{"title"=>"Close", "action"=>"CloseDoc"}],
"menu"=>"File"}
Json.deserialise(http_response).should eq(result)
end

it "should know how to convert json to a hashmap" do
hash = {
"menu"=>"File",
"commands"=>[{
"title"=>"New",
"title"=>"New",
"action"=>"CreateDoc"},
{
"title"=>"Open",
Expand All @@ -43,12 +43,12 @@ module Wrest::Components::Translators
Json.serialise(hash).should include("\"menu\":\"File\"")
Json.serialise(hash).should include("\"commands\":[{\"title\":\"New\",\"action\":\"CreateDoc\"},{\"title\":\"Open\",\"action\":\"OpenDoc\"},{\"title\":\"Close\",\"action\":\"CloseDoc\"}]")
end

it "has #deserialize delegate to #deserialise" do
Json.should_receive(:deserialise).with(http_response, :option => :something)
Json.deserialize(http_response, :option => :something)
end

it "has #serialize delegate to #serialise" do
Json.should_receive(:serialise).with({ :hash => :foo }, :option => :something)
Json.serialize({:hash => :foo}, :option => :something)
Expand Down
4 changes: 2 additions & 2 deletions spec/wrest/components/translators/txt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ module Wrest::Components::Translators
it "should return string version of any object when serialise" do
Txt.serialise({"ooga"=>{"age" => "12"}}).should == "{\"ooga\"=>{\"age\"=>\"12\"}}"
end

it "has #deserialize delegate to #deserialise" do
Txt.should_receive(:deserialise).with(http_response, :option => :something)
Txt.deserialize(http_response, :option => :something)
end

it "has #serialize delegate to #serialise" do
Txt.should_receive(:serialise).with({ :hash => :foo }, :option => :something)
Txt.serialize({:hash => :foo}, :option => :something)
Expand Down
18 changes: 9 additions & 9 deletions spec/wrest/components/translators/xml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,39 @@ module Wrest::Components::Translators
it "should know how to convert a hashmap to xml" do
Xml.serialise({"ooga"=>{"age" => "12"}}).should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n <ooga>\n <age>12</age>\n </ooga>\n</hash>\n"
end

it "should call filter only if xpath is specified" do
http_response.should_receive(:body)
ActiveSupport::XmlMini.should_receive(:filter)
Xml.deserialise(http_response,{:xpath=>'//age'})
end


it "should not call filter if xpath is not specified" do
http_response.should_receive(:body).and_return("<Person><Personal><Name><FirstName>Nikhil</FirstName></Name></Personal><Address><Name>Bangalore</Name></Address></Person>")
Xml.should_not_receive(:filter)

Xml.deserialise(http_response)
end
Helpers.xml_backends.each do |e|

Helpers.xml_backends.each do |e|
it "should be able to pull out desired elements from an xml response based on xpath and return an array of matching nodes" do
ActiveSupport::XmlMini.backend = e

http_response.should_receive(:body).and_return("<Person><Personal><Name><FirstName>Nikhil</FirstName></Name></Personal><Address><Name>Bangalore</Name></Address></Person>")

res_arr = Xml.deserialise(http_response,{:xpath=>'//Name'})
result = ""
res_arr.each { |a| result+= a.to_s.gsub(/[\n]+/, "").gsub(/\s/, '')}
result.should == "<Name><FirstName>Nikhil</FirstName></Name><Name>Bangalore</Name>"
result.should == "<Name><FirstName>Nikhil</FirstName></Name><Name>Bangalore</Name>"
end
end

it "has #deserialize delegate to #deserialise" do
Xml.should_receive(:deserialise).with(http_response, :option => :something)
Xml.deserialize(http_response, :option => :something)
end

it "has #serialize delegate to #serialise" do
Xml.should_receive(:serialise).with({ :hash => :foo }, :option => :something)
Xml.serialize({:hash => :foo}, :option => :something)
Expand Down
Loading

0 comments on commit 0a78782

Please sign in to comment.