Navigation Menu

Skip to content

Commit

Permalink
fixing test suite to work with the latest version of rspec
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Bedra committed May 22, 2009
1 parent abf0347 commit cdeb5d0
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 84 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -50,7 +50,7 @@ Spec::Rake::SpecTask.new('spec') do |t|
end

RCov::VerifyTask.new(:verify_coverage => :specs_with_rcov) do |t|
t.threshold = 97.0
t.threshold = 97.03
t.index_html = 'coverage/index.html'
end

Expand Down
4 changes: 2 additions & 2 deletions castronaut.rb
@@ -1,6 +1,6 @@
require 'rubygems'
gem :activerecord, '>= 2.1.0'
gem :activesupport, '>= 2.1.0'
gem 'activerecord', '>= 2.1.0'
gem 'activesupport', '>= 2.1.0'

require 'active_support'
require 'activerecord'
Expand Down
2 changes: 1 addition & 1 deletion spec/castronaut/adapters/development/user_spec.rb
Expand Up @@ -42,7 +42,7 @@
describe "when the credentials are invalid" do

it "returns a Castronaut::AuthenticationResult object with the unable to authenticate user message" do
Castronaut::Adapters::Development::User.stub!(:find_by_login).and_return(stub_everything(:crypted_password => "a", :salt => "b"))
Castronaut::Adapters::Development::User.stub!(:find_by_login).and_return(stub(:crypted_password => "a", :salt => "b").as_null_object)
Castronaut::Adapters::Development::User.authenticate('bob', '1234').error_message.should == "Unable to authenticate the username bob"
end

Expand Down
4 changes: 2 additions & 2 deletions spec/castronaut/adapters/ldap/user_spec.rb
Expand Up @@ -5,14 +5,14 @@
describe "authenticate" do

it "attempts to authenticate the user" do
connection = stub_everything
connection = stub({}).as_null_object
Net::LDAP.stub!(:new).and_return(connection)
connection.should_receive(:authenticate).with('cn=bob, dc=example, dc=com, ', '1234').and_return(nil)
Castronaut::Adapters::Ldap::User.authenticate('cn=bob, dc=example, dc=com', '1234')
end

it "returns a failed to authenticate message when authentication fails" do
connection = stub_everything
connection = stub({}).as_null_object
Net::LDAP.stub!(:new).and_return(connection)
connection.stub!(:authenticate).and_return(nil)
connection.stub!(:bind).and_return(false)
Expand Down
Expand Up @@ -85,7 +85,7 @@
describe "when the credentials are invalid" do

it "returns a Castronaut::AuthenticationResult object with the unable to authenticate user message" do
Castronaut::Adapters::RestfulAuthentication::User.stub!(:find_by_login).and_return(stub_everything(:crypted_password => "a", :salt => "b"))
Castronaut::Adapters::RestfulAuthentication::User.stub!(:find_by_login).and_return(stub(:crypted_password => "a", :salt => "b").as_null_object)
Castronaut::Adapters::RestfulAuthentication::User.authenticate('bob', '1234').error_message.should == "Unable to authenticate the username bob"
end

Expand Down
12 changes: 6 additions & 6 deletions spec/castronaut/configuration_spec.rb
Expand Up @@ -15,7 +15,7 @@
config = Castronaut::Configuration.new
config.stub!(:parse_config_into_settings)
config.stub!(:connect_activerecord)
config.stub!(:setup_logger).and_return(stub_everything)
config.stub!(:setup_logger).and_return(stub({}).as_null_object)
Castronaut::Configuration.stub!(:new).and_return(config)

Castronaut::Configuration.load.config_file_path.should == './castronaut.yml'
Expand All @@ -27,7 +27,7 @@
config = Castronaut::Configuration.new
config.stub!(:parse_config_into_settings)
config.stub!(:connect_activerecord)
config.stub!(:setup_logger).and_return(stub_everything)
config.stub!(:setup_logger).and_return(stub({}).as_null_object)
Castronaut::Configuration.stub!(:new).and_return(config)

Castronaut::Configuration.load("/foo/bar/baz").config_file_path.should == '/foo/bar/baz'
Expand All @@ -39,7 +39,7 @@
config = Castronaut::Configuration.new
config.stub!(:parse_config_into_settings)
config.stub!(:connect_activerecord)
config.stub!(:setup_logger).and_return(stub_everything)
config.stub!(:setup_logger).and_return(stub({}).as_null_object)
Castronaut::Configuration.stub!(:new).and_return(config)

Castronaut::Configuration.load(@test_config_file)
Expand All @@ -52,7 +52,7 @@
config = Castronaut::Configuration.new
config.stub!(:parse_config_into_settings)
config.stub!(:connect_activerecord)
config.stub!(:setup_logger).and_return(stub_everything)
config.stub!(:setup_logger).and_return(stub({}).as_null_object)
Castronaut::Configuration.stub!(:new).and_return(config)

Castronaut::Configuration.load(@test_config_file).config_hash = config_hash
Expand All @@ -72,7 +72,7 @@
config = Castronaut::Configuration.new
config.stub!(:connect_activerecord)
Castronaut::Configuration.stub!(:new).and_return(config)
Hodel3000CompliantLogger.should_receive(:new).with("log/castronaut.log", anything).and_return(stub_everything)
Hodel3000CompliantLogger.should_receive(:new).with("log/castronaut.log", anything).and_return(stub({}).as_null_object)

Castronaut::Configuration.load(@test_config_file)
end
Expand All @@ -90,7 +90,7 @@
config.stub!(:connect_activerecord)
Castronaut::Configuration.stub!(:new).and_return(config)

Hodel3000CompliantLogger.should_receive(:new).with("log/castronaut.log", "daily").and_return(stub_everything)
Hodel3000CompliantLogger.should_receive(:new).with("log/castronaut.log", "daily").and_return(stub({}).as_null_object)

Castronaut::Configuration.load(@test_config_file)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/castronaut/models/login_ticket_spec.rb
Expand Up @@ -70,7 +70,7 @@
describe "and it has already been consumed" do

it "returns a ticket result with the AlreadyConsumedMessage" do
login_ticket = stub_everything(:consumed? => true)
login_ticket = stub(:consumed? => true).as_null_object

Castronaut::TicketResult.should_receive(:new).with(login_ticket, LoginTicket::AlreadyConsumedMessage)
LoginTicket.stub!(:find_by_ticket).and_return(login_ticket)
Expand Down
68 changes: 34 additions & 34 deletions spec/castronaut/models/proxy_granting_ticket_spec.rb
Expand Up @@ -69,7 +69,7 @@
describe "when proxy granting ticket url is valid" do

it "creates a new net/http connection to uri host and port" do
https = stub_everything
https = stub({}).as_null_object
Net::HTTP.stub!(:new).and_return(https)

uri = stub('uri', :host => 'example.com', :port => 443, :path => '')
Expand All @@ -80,10 +80,10 @@
end

it "sets the new net/http connection to use ssl" do
https = stub_everything
https = stub({}).as_null_object
Net::HTTP.stub!(:new).and_return(https)

uri = stub_everything(:host => 'example.com', :port => 443, :path => '')
uri = stub(:host => 'example.com', :port => 443, :path => '').as_null_object
URI.stub!(:parse).and_return(uri)

https.should_receive(:use_ssl=).with(true)
Expand All @@ -94,10 +94,10 @@
end

it "starts the connection" do
https = stub_everything
https = stub({}).as_null_object
Net::HTTP.stub!(:new).and_return(https)

uri = stub_everything(:host => 'example.com', :port => 443, :path => '')
uri = stub(:host => 'example.com', :port => 443, :path => '').as_null_object
URI.stub!(:parse).and_return(uri)

https.should_receive(:start)
Expand All @@ -108,58 +108,58 @@
describe "inside the http connection block" do

it "intializes a new proxy granting ticket" do
https = stub_everything
https = stub({}).as_null_object
Net::HTTP.stub!(:new).and_return(https)

uri = stub_everything(:host => 'example.com', :port => 443, :path => '')
uri = stub(:host => 'example.com', :port => 443, :path => '').as_null_object
URI.stub!(:parse).and_return(uri)

https.stub!(:start).and_yield(stub_everything(:request_get => stub_everything))
https.stub!(:start).and_yield(stub(:request_get => stub({}).as_null_object).as_null_object)

ProxyGrantingTicket.should_receive(:new).with(:service_ticket => 'service ticket', :client_hostname => '10.1.1.1').and_return(stub_everything)
ProxyGrantingTicket.should_receive(:new).with(:service_ticket => 'service ticket', :client_hostname => '10.1.1.1').and_return(stub({}).as_null_object)
ProxyGrantingTicket.generate_ticket('http://example.com', '10.1.1.1', 'service ticket')
end

it "dispenses a new ticket for the proxy granting ticket" do
https = stub_everything
https = stub({}).as_null_object
Net::HTTP.stub!(:new).and_return(https)

uri = stub_everything(:host => 'example.com', :port => 443, :path => '')
uri = stub(:host => 'example.com', :port => 443, :path => '').as_null_object
URI.stub!(:parse).and_return(uri)

https.stub!(:start).and_yield(stub_everything(:request_get => stub_everything))
https.stub!(:start).and_yield(stub(:request_get => stub({}).as_null_object).as_null_object)

proxy_granting_ticket = stub_everything
proxy_granting_ticket = stub({}).as_null_object
proxy_granting_ticket.should_receive(:dispense_ticket)
ProxyGrantingTicket.stub!(:new).and_return(proxy_granting_ticket)

ProxyGrantingTicket.generate_ticket('http://example.com', '10.1.1.1', 'service ticket')
end

it "dispenses a new iou for the proxy granting ticket" do
https = stub_everything
https = stub({}).as_null_object
Net::HTTP.stub!(:new).and_return(https)

uri = stub_everything(:host => 'example.com', :port => 443, :path => '')
uri = stub(:host => 'example.com', :port => 443, :path => '').as_null_object
URI.stub!(:parse).and_return(uri)

https.stub!(:start).and_yield(stub_everything(:request_get => stub_everything))
https.stub!(:start).and_yield(stub(:request_get => stub({}).as_null_object).as_null_object)

proxy_granting_ticket = stub_everything
proxy_granting_ticket = stub({}).as_null_object
proxy_granting_ticket.should_receive(:dispense_iou)
ProxyGrantingTicket.stub!(:new).and_return(proxy_granting_ticket)

ProxyGrantingTicket.generate_ticket('http://example.com', '10.1.1.1', 'service ticket')
end

it "requests the proxy granting ticket path via GET" do
https = stub_everything
https = stub({}).as_null_object
Net::HTTP.stub!(:new).and_return(https)

uri = stub_everything(:host => 'example.com', :port => 443, :path => '')
uri = stub(:host => 'example.com', :port => 443, :path => '').as_null_object
URI.stub!(:parse).and_return(uri)
http_connection = mock('httpconnection')
http_connection.should_receive(:request_get).with('/?pgtId=PGT-RANDOM&pgtIou=PGTIOU-RANDOM').and_return(stub_everything)
http_connection.should_receive(:request_get).with('/?pgtId=PGT-RANDOM&pgtIou=PGTIOU-RANDOM').and_return(stub({}).as_null_object)

https.stub!(:start).and_yield(http_connection)

Expand All @@ -171,7 +171,7 @@
describe "when the request to the proxy granting ticket path is successful" do

it "saves the proxy granting ticket" do
https = stub_everything
https = stub({}).as_null_object
Net::HTTP.stub!(:new).and_return(https)

uri = stub('uri', :host => 'example.com', :port => 443, :path => '', :query => '')
Expand All @@ -191,7 +191,7 @@
describe "returns a ticket result" do

it "with the proxy granting ticket" do
https = stub_everything
https = stub({}).as_null_object
Net::HTTP.stub!(:new).and_return(https)

uri = stub('uri', :host => 'example.com', :port => 443, :path => '', :query => '')
Expand All @@ -207,10 +207,10 @@
end

it "with a proxy granting ticket generated message" do
https = stub_everything
https = stub({}).as_null_object
Net::HTTP.stub!(:new).and_return(https)

uri = stub_everything(:host => 'example.com', :port => 443, :path => '')
uri = stub(:host => 'example.com', :port => 443, :path => '').as_null_object
URI.stub!(:parse).and_return(uri)
http_connection = mock('httpconnection')
http_connection.stub!(:request_get).and_return(stub('request', :code => '200'))
Expand All @@ -223,16 +223,16 @@
end

it "with a message category of success" do
https = stub_everything
https = stub({}).as_null_object
Net::HTTP.stub!(:new).and_return(https)

uri = stub_everything(:host => 'example.com', :port => 443, :path => '')
uri = stub(:host => 'example.com', :port => 443, :path => '').as_null_object
URI.stub!(:parse).and_return(uri)
http_connection = mock('httpconnection')
http_connection.stub!(:request_get).and_return(stub('request', :code => '200'))
https.stub!(:start).and_yield(http_connection)

proxy_granting_ticket = stub_everything(:iou => 'PGTIOU-RANDOM', :ticket => 'PGT-RANDOM', :save! => true)
proxy_granting_ticket = stub(:iou => 'PGTIOU-RANDOM', :ticket => 'PGT-RANDOM', :save! => true).as_null_object
ProxyGrantingTicket.stub!(:new).and_return(proxy_granting_ticket)

ProxyGrantingTicket.generate_ticket('http://example.com', '10.1.1.1', 'service ticket').message_category.should == 'success'
Expand All @@ -247,32 +247,32 @@
describe "returns a ticket result" do

it "with a proxy granting ticket generated message" do
https = stub_everything
https = stub({}).as_null_object
Net::HTTP.stub!(:new).and_return(https)

uri = stub_everything(:host => 'example.com', :port => 443, :path => '')
uri = stub(:host => 'example.com', :port => 443, :path => '').as_null_object
URI.stub!(:parse).and_return(uri)
http_connection = mock('httpconnection')
http_connection.stub!(:request_get).and_return(stub('request', :code => '404'))
https.stub!(:start).and_yield(http_connection)

proxy_granting_ticket = stub_everything(:iou => 'PGTIOU-RANDOM', :ticket => 'PGT-RANDOM', :save! => true, :inspect => 'PGT-INSPECT')
proxy_granting_ticket = stub(:iou => 'PGTIOU-RANDOM', :ticket => 'PGT-RANDOM', :save! => true, :inspect => 'PGT-INSPECT').as_null_object
ProxyGrantingTicket.stub!(:new).and_return(proxy_granting_ticket)

ProxyGrantingTicket.generate_ticket('http://example.com', '10.1.1.1', 'service ticket').message.should == "PGT callback server responded with a bad result code '404'. PGT will not be stored."
end

it "with a message category of success" do
https = stub_everything
https = stub({}).as_null_object
Net::HTTP.stub!(:new).and_return(https)

uri = stub_everything(:host => 'example.com', :port => 443, :path => '')
uri = stub(:host => 'example.com', :port => 443, :path => '').as_null_object
URI.stub!(:parse).and_return(uri)
http_connection = mock('httpconnection')
http_connection.stub!(:request_get).and_return(stub_everything(:code => '404'))
http_connection.stub!(:request_get).and_return(stub(:code => '404').as_null_object)
https.stub!(:start).and_yield(http_connection)

proxy_granting_ticket = stub_everything(:iou => 'PGTIOU-RANDOM', :ticket => 'PGT-RANDOM', :save! => true)
proxy_granting_ticket = stub(:iou => 'PGTIOU-RANDOM', :ticket => 'PGT-RANDOM', :save! => true).as_null_object
ProxyGrantingTicket.stub!(:new).and_return(proxy_granting_ticket)

ProxyGrantingTicket.generate_ticket('http://example.com', '10.1.1.1', 'service ticket').message_category.should == 'warn'
Expand Down
2 changes: 1 addition & 1 deletion spec/castronaut/models/proxy_ticket_spec.rb
Expand Up @@ -16,7 +16,7 @@
describe "validating ticket" do

it "validates the service and ticket using the service ticket validator" do
ServiceTicket.should_receive(:validate_ticket).with('service', 'ticket', true).and_return(stub_everything(:invalid? => true))
ServiceTicket.should_receive(:validate_ticket).with('service', 'ticket', true).and_return(stub(:invalid? => true).as_null_object)
ProxyTicket.validate_ticket('service', 'ticket')
end

Expand Down
8 changes: 4 additions & 4 deletions spec/castronaut/models/service_ticket_spec.rb
Expand Up @@ -114,7 +114,7 @@
describe "when the service and ticket are given" do

it "attempts to find the ServiceTicket by the given ticket" do
Castronaut::Models::ServiceTicket.should_receive(:find_by_ticket).with('ticket').and_return(stub_everything)
Castronaut::Models::ServiceTicket.should_receive(:find_by_ticket).with('ticket').and_return(stub({}).as_null_object)
Castronaut::Models::ServiceTicket.validate_ticket('service', 'ticket')
end

Expand Down Expand Up @@ -142,17 +142,17 @@
describe "when it is already consumed it returns a ticket result" do

it "with the ticket used up message" do
Castronaut::Models::ServiceTicket.stub!(:find_by_ticket).and_return(stub_everything(:consumed? => true))
Castronaut::Models::ServiceTicket.stub!(:find_by_ticket).and_return(stub(:consumed? => true).as_null_object)
Castronaut::Models::ServiceTicket.validate_ticket('service', 'ticket').message.should == "Ticket 'ticket' has already been used up."
end

it "with the INVALID_TICKET message category" do
Castronaut::Models::ServiceTicket.stub!(:find_by_ticket).and_return(stub_everything(:consumed? => true))
Castronaut::Models::ServiceTicket.stub!(:find_by_ticket).and_return(stub(:consumed? => true).as_null_object)
Castronaut::Models::ServiceTicket.validate_ticket('service', 'ticket').message_category.should == 'INVALID_TICKET'
end

it "is marked as invalid" do
Castronaut::Models::ServiceTicket.stub!(:find_by_ticket).and_return(stub_everything(:consumed? => true))
Castronaut::Models::ServiceTicket.stub!(:find_by_ticket).and_return(stub(:consumed? => true).as_null_object)
Castronaut::Models::ServiceTicket.validate_ticket('service', 'ticket').should be_invalid
end

Expand Down
4 changes: 2 additions & 2 deletions spec/castronaut/presenters/login_spec.rb
Expand Up @@ -47,7 +47,7 @@

it "validates the ticket generating ticket" do
@controller.request.cookies['tgt'] = 'fake cookie'
Castronaut::Models::TicketGrantingTicket.should_receive(:validate_cookie).with('fake cookie').and_return(Castronaut::TicketResult.new(stub_everything))
Castronaut::Models::TicketGrantingTicket.should_receive(:validate_cookie).with('fake cookie').and_return(Castronaut::TicketResult.new(stub({}).as_null_object))
Castronaut::Presenters::Login.new(@controller).represent!
end

Expand Down Expand Up @@ -143,7 +143,7 @@
describe "login ticket generation" do

it "generates a new login ticket when you call :login_ticket" do
Castronaut::Models::LoginTicket.should_receive(:generate_from).and_return(stub_everything(:ticket => 'ticket'))
Castronaut::Models::LoginTicket.should_receive(:generate_from).and_return(stub(:ticket => 'ticket').as_null_object)
Castronaut::Presenters::Login.new(@controller).login_ticket
end

Expand Down
2 changes: 1 addition & 1 deletion spec/castronaut/presenters/logout_spec.rb
Expand Up @@ -24,7 +24,7 @@
end

it "generates a new login ticket when you call :login_ticket" do
Castronaut::Models::LoginTicket.should_receive(:generate_from).and_return(stub_everything(:ticket => 'ticket'))
Castronaut::Models::LoginTicket.should_receive(:generate_from).and_return(stub(:ticket => 'ticket').as_null_object)
Castronaut::Presenters::Logout.new(@controller).login_ticket
end

Expand Down

0 comments on commit cdeb5d0

Please sign in to comment.