Permalink
Browse files

Switch from riot to rspec

  • Loading branch information...
1 parent 1532408 commit 8748f753c7b071aaf2cedf94d72804ac6517a30d @soupmatt soupmatt committed Oct 23, 2011
Showing with 222 additions and 219 deletions.
  1. +2 −0 .rspec
  2. +3 −4 Gemfile
  3. +13 −8 Gemfile.lock
  4. +19 −13 Rakefile
  5. +169 −0 spec/casclient/frameworks/rails/filter_spec.rb
  6. +16 −0 spec/spec_helper.rb
  7. +0 −10 test/teststrap.rb
  8. +0 −184 test/units/casclient/frameworks/rails/filter_test.rb
View
@@ -0,0 +1,2 @@
+--format nested
+--color
View
@@ -1,13 +1,12 @@
source "http://rubygems.org"
group :development do
- gem "riot"
- gem "rr"
+ gem "rspec", "~> 2.7.0"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.6.2"
- gem "rcov"
gem "actionpack"
+ gem "rcov"
end
-gem "activesupport"
+gem "activesupport", :require => "active_support"
View
@@ -5,17 +5,23 @@ GEM
activesupport (= 2.3.11)
rack (~> 1.1.0)
activesupport (2.3.11)
+ diff-lcs (1.1.3)
git (1.2.5)
- jeweler (1.6.2)
+ jeweler (1.6.4)
bundler (~> 1.0)
git (>= 1.2.5)
rake
rack (1.1.2)
- rake (0.9.2)
- rcov (0.9.9)
- riot (0.12.5)
- rr
- rr (1.0.4)
+ rake (0.9.2.2)
+ rcov (0.9.11)
+ rspec (2.7.0)
+ rspec-core (~> 2.7.0)
+ rspec-expectations (~> 2.7.0)
+ rspec-mocks (~> 2.7.0)
+ rspec-core (2.7.1)
+ rspec-expectations (2.7.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.7.0)
PLATFORMS
ruby
@@ -26,5 +32,4 @@ DEPENDENCIES
bundler (~> 1.0.0)
jeweler (~> 1.6.2)
rcov
- riot
- rr
+ rspec (~> 2.7.0)
View
@@ -24,23 +24,29 @@ Jeweler::Tasks.new do |gem|
end
Jeweler::RubygemsDotOrgTasks.new
-require 'rake/testtask'
-Rake::TestTask.new(:test) do |test|
- test.libs << 'test'
- test.pattern = 'test/**/*_test.rb'
- test.verbose = true
+begin
+ require 'rcov/rcovtask'
+ Rcov::RcovTask.new do |test|
+ test.libs << 'test'
+ test.pattern = 'test/**/test_*.rb'
+ test.verbose = true
+ test.rcov_opts << '--exclude "gems/*"'
+ end
+rescue LoadError
+ puts "Hiding rcov tasks because rcov is not available"
end
-require 'rcov/rcovtask'
-Rcov::RcovTask.new do |test|
- test.libs << 'test'
- test.pattern = 'test/**/test_*.rb'
- test.verbose = true
- test.rcov_opts << '--exclude "gems/*"'
+begin
+ require 'rspec/core/rake_task'
+ desc 'Run RSpecs to confirm that all functionality is working as expected'
+ RSpec::Core::RakeTask.new('spec') do |t|
+ t.pattern = 'spec/**/*_spec.rb'
+ end
+ task :default => :spec
+rescue LoadError
+ puts "Hiding spec tasks because RSpec is not available"
end
-task :default => :test
-
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
@@ -0,0 +1,169 @@
+require 'spec_helper'
+require 'action_controller'
+require 'casclient/frameworks/rails/filter'
+
+describe CASClient::Frameworks::Rails::Filter do
+
+ def controller_with_session(request = nil, session={})
+ request ||= mock_post_request
+ controller = double("Controller")
+ controller.stub(:session) {session}
+ controller.stub(:request) {request}
+ controller.stub(:url_for) {"bogusurl"}
+ controller.stub(:params) {{:ticket => "bogusticket", :renew => false}}
+ controller
+ end
+
+ def mock_post_request
+ mock_request = ActionController::Request.new({})
+ mock_request.stub(:post?) {true}
+ mock_request
+ end
+
+ before(:each) do
+ CASClient::Frameworks::Rails::Filter.configure(
+ :cas_base_url => 'http://test.local/',
+ :logger => double("Logger")
+ )
+ end
+
+ describe "#fake" do
+ subject { Hash.new }
+ context "fake user without attributes" do
+ before { CASClient::Frameworks::Rails::Filter.fake('tester@test.com') }
+ it 'should set the session user on #filter' do
+ CASClient::Frameworks::Rails::Filter.filter(controller_with_session(nil, subject))
+ subject.should eq({:cas_user => 'tester@test.com', :casfilteruser => 'tester@test.com'})
+ end
+ after { CASClient::Frameworks::Rails::Filter.fake(nil,nil) }
+ end
+
+ context "fake user with attributes" do
+ before { CASClient::Frameworks::Rails::Filter.fake('tester@test.com', {:test => 'stuff', :this => 'that'}) }
+ it 'should set the session user and attributes on #filter' do
+ CASClient::Frameworks::Rails::Filter.filter(controller_with_session(nil, subject))
+ subject.should eq({ :cas_user => 'tester@test.com', :casfilteruser => 'tester@test.com', :cas_extra_attributes => {:test => 'stuff', :this => 'that' }})
+ end
+ after { CASClient::Frameworks::Rails::Filter.fake(nil,nil) }
+ end
+ end
+
+ context "new valid service ticket" do
+ it "should return successfully from filter" do
+
+ pgt = CASClient::ProxyGrantingTicket.new(
+ "PGT-1308586001r9573FAD5A8C62E134A4AA93273F226BD3F0C3A983DCCCD176",
+ "PGTIOU-1308586001r29DC1F852C95930FE6694C1EFC64232A3359798893BC0B")
+
+ raw_text = "<cas:serviceResponse xmlns:cas=\"http://www.yale.edu/tp/cas\">
+ <cas:authenticationSuccess>
+ <cas:user>rich.yarger@vibes.com</cas:user>
+ <cas:proxyGrantingTicket>PGTIOU-1308586001r29DC1F852C95930FE6694C1EFC64232A3359798893BC0B</cas:proxyGrantingTicket>
+ </cas:authenticationSuccess>
+ </cas:serviceResponse>"
+ response = CASClient::ValidationResponse.new(raw_text)
+
+ CASClient::Client.any_instance.stub(:request_cas_response).and_return(response)
+ CASClient::Client.any_instance.stub(:retrieve_proxy_granting_ticket).and_return(pgt)
+
+ controller = controller_with_session()
+ CASClient::Frameworks::Rails::Filter.filter(controller).should eq(true)
+ end
+ end
+
+ context "new service ticket with invalid service ticket" do
+ it "should return failure from filter" do
+
+ raw_text = "<cas:serviceResponse xmlns:cas=\"http://www.yale.edu/tp/cas\">
+ <cas:authenticationFailure>Some Error Text</cas:authenticationFailure>
+ </cas:serviceResponse>"
+ response = CASClient::ValidationResponse.new(raw_text)
+
+ CASClient::Client.any_instance.stub(:request_cas_response).and_return(response)
+ CASClient::Frameworks::Rails::Filter.stub(:unauthorized!) {"bogusresponse"}
+
+ controller = controller_with_session()
+ CASClient::Frameworks::Rails::Filter.filter(controller).should eq(false)
+ end
+ end
+
+ context "no new service ticket but with last service ticket" do
+ it "should return failure from filter" do
+
+ CASClient::Frameworks::Rails::Filter.stub(:unauthorized!) {"bogusresponse"}
+
+ controller = controller_with_session()
+ controller.stub(:params) {{}}
+ CASClient::Frameworks::Rails::Filter.filter(controller).should eq(false)
+ end
+ end
+
+ context "no new service ticket sent through gateway, gatewaying off" do
+ it "should return failure from filter" do
+
+ CASClient::Frameworks::Rails::Filter.stub(:unauthorized!) {"bogusresponse"}
+
+ CASClient::Frameworks::Rails::Filter.config[:use_gatewaying] = false
+ controller = controller_with_session()
+ controller.session[:cas_sent_to_gateway] = true
+ controller.stub(:params) {{}}
+ CASClient::Frameworks::Rails::Filter.filter(controller).should eq(false)
+ end
+ end
+
+ context "no new service ticket sent through gateway, gatewaying on" do
+ it "should return failure from filter" do
+
+ CASClient::Frameworks::Rails::Filter.config[:use_gatewaying] = true
+ controller = controller_with_session()
+ controller.session[:cas_sent_to_gateway] = true
+ controller.stub(:params) {{}}
+ CASClient::Frameworks::Rails::Filter.filter(controller).should eq(true)
+ end
+ end
+
+ context "new service ticket with no PGT" do
+ it "should return failure from filter" do
+
+ raw_text = "<cas:serviceResponse xmlns:cas=\"http://www.yale.edu/tp/cas\">
+ <cas:authenticationSuccess>
+ <cas:user>rich.yarger@vibes.com</cas:user>
+ <cas:proxyGrantingTicket>PGTIOU-1308586001r29DC1F852C95930FE6694C1EFC64232A3359798893BC0B</cas:proxyGrantingTicket>
+ </cas:authenticationSuccess>
+ </cas:serviceResponse>"
+ response = CASClient::ValidationResponse.new(raw_text)
+
+ CASClient::Client.any_instance.stub(:request_cas_response).and_return(response)
+ CASClient::Client.any_instance.stub(:retrieve_proxy_granting_ticket).and_raise CASClient::CASException
+
+ controller = controller_with_session()
+ expect { CASClient::Frameworks::Rails::Filter.filter(controller) }.to raise_error(CASClient::CASException)
+ end
+ end
+
+ context "new service ticket, but cannot connect to CASServer" do
+ it "should return failure from filter" do
+
+ CASClient::Client.any_instance.stub(:request_cas_response).and_raise "Some exception"
+
+ controller = controller_with_session()
+ expect { CASClient::Frameworks::Rails::Filter.filter(controller) }.to raise_error(RuntimeError)
+ end
+ end
+
+ context "reuse service ticket successfully" do
+ subject { Hash.new }
+ it "should return successfully from filter" do
+
+ mock_client = CASClient::Client.new()
+ mock_client.should_receive(:request_cas_response).at_most(0).times
+ mock_client.should_receive(:retrieve_proxy_granting_ticket).at_most(0).times
+ CASClient::Frameworks::Rails::Filter.send(:class_variable_set, :@@client, mock_client)
+
+ subject[:cas_last_valid_ticket] = 'bogusticket'
+ subject[:cas_last_valid_ticket_service] = 'bogusurl'
+ controller = controller_with_session(mock_post_request(), subject)
+ CASClient::Frameworks::Rails::Filter.filter(controller).should eq(true)
+ end
+ end
+end
View
@@ -0,0 +1,16 @@
+require 'bundler'
+
+Bundler.setup(:default, :test)
+Bundler.require
+
+RSpec.configure do |config|
+ #config.include Rack::Test::Methods
+ #config.include Webrat::Methods
+ #config.include Webrat::Matchers
+ #config.include TestHelpers
+ #config.include Helpers
+ config.mock_with :rspec
+ config.mock_framework = :rspec
+end
+
+require 'rubycas-client'
View
@@ -1,10 +0,0 @@
-require 'rubygems'
-require 'bundler/setup'
-require 'casclient'
-require 'riot'
-require 'riot/rr'
-require 'action_pack'
-
-RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
-
-Riot.reporter = Riot::VerboseStoryReporter
Oops, something went wrong.

0 comments on commit 8748f75

Please sign in to comment.