Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Switch to rspec.

  • Loading branch information...
commit 2799c9c112941c0d213490760d61b88a2faa11ad 1 parent 1e9e8d4
@tobias authored
View
32 Rakefile
@@ -10,9 +10,8 @@ begin
gem.email = "tcrawley@gmail.com"
gem.homepage = "http://github.com/tobias/zendesk_remote_auth"
gem.authors = ["Tobias Crawley"]
- gem.add_development_dependency "thoughtbot-shoulda"
- gem.add_development_dependency "mocha"
- gem.add_development_dependency "matchy"
+ gem.add_dependency "active_support", ">= 3.0.0"
+ gem.add_development_dependency "rspec", ">= 2.6.0"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
@@ -20,29 +19,18 @@ rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end
-require 'rake/testtask'
-Rake::TestTask.new(:test) do |test|
- test.libs << 'lib' << 'test'
- test.pattern = 'test/**/*_test.rb'
- test.verbose = true
+require 'rspec/core'
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new(:spec) do |spec|
+ spec.pattern = FileList['spec/**/*_spec.rb']
end
-begin
- require 'rcov/rcovtask'
- Rcov::RcovTask.new do |test|
- test.libs << 'test'
- test.pattern = 'test/**/*_test.rb'
- test.verbose = true
- end
-rescue LoadError
- task :rcov do
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
- end
+RSpec::Core::RakeTask.new(:rcov) do |spec|
+ spec.pattern = 'spec/**/*_spec.rb'
+ spec.rcov = true
end
-task :test => :check_dependencies
-
-task :default => :test
+task :default => :spec
begin
require 'yard'
View
2  lib/zendesk_remote_auth.rb
@@ -1,5 +1,5 @@
require 'digest/md5'
-require 'active_support' #gives us Hash.to_query
+require 'active_support/core_ext/object' #gives us Hash.to_query
##
# Provides a helper to use Zendesk's SSO/remote auth service.
View
8 test/test_helper.rb → spec/spec_helper.rb
@@ -1,12 +1,4 @@
-require 'rubygems'
-require 'test/unit'
-require 'shoulda'
-require 'mocha'
-require 'matchy'
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'zendesk_remote_auth'
-class Test::Unit::TestCase
-end
View
64 test/zendesk_remote_auth_test.rb → spec/zendesk_remote_auth_spec.rb
@@ -1,36 +1,32 @@
-require 'test_helper'
+require 'spec_helper'
-class ZendeskRemoteAuthTest < Test::Unit::TestCase
+describe Zendesk::RemoteAuth do
- def setup
+ before(:each) do
@auth = Object.new
@auth.extend(Zendesk::RemoteAuthHelper)
end
context 'RemoteAuth' do
- setup do
+ before(:each) do
Zendesk::RemoteAuth.token = Zendesk::RemoteAuth.auth_url = nil
end
- should 'raise exception if token is not set' do
- assert_raise ArgumentError do
- Zendesk::RemoteAuth.token
- end
+ it 'should raise exception if token is not set' do
+ lambda{ Zendesk::RemoteAuth.token }.should raise_error(ArgumentError)
end
- should 'return the token without exception if it is set' do
+ it 'should return the token without exception if it is set' do
Zendesk::RemoteAuth.token = 'blah'
Zendesk::RemoteAuth.token.should == 'blah'
end
- should 'raise exception if auth_url is not set' do
- assert_raise ArgumentError do
- Zendesk::RemoteAuth.auth_url
- end
+ it 'should raise exception if auth_url is not set' do
+ lambda { Zendesk::RemoteAuth.auth_url }.should raise_error(ArgumentError)
end
- should 'return the auth_url without exception if it is set' do
+ it 'should return the auth_url without exception if it is set' do
Zendesk::RemoteAuth.auth_url = 'blah'
Zendesk::RemoteAuth.auth_url.should == 'blah'
end
@@ -38,69 +34,69 @@ def setup
context 'url generation' do
- setup do
+ before(:each) do
Zendesk::RemoteAuth.token = 'the_token'
Zendesk::RemoteAuth.auth_url = 'the_url'
@valid_params = { :email => 'test@example.com', :name => 'blah'}
end
context 'required fields' do
- should 'raise an argument error the name is not provided' do
- assert_raise ArgumentError do
+ it 'should raise an argument error the name is not provided' do
+ lambda {
@valid_params.delete(:name)
@auth.zendesk_remote_auth_url(@valid_params)
- end
+ }.should raise_error(ArgumentError)
end
- should 'raise an argument error the email is not provided' do
- assert_raise ArgumentError do
+ it 'should raise an argument error the email is not provided' do
+ lambda {
@valid_params.delete(:email)
@auth.zendesk_remote_auth_url(@valid_params)
- end
+ }.should raise_error(ArgumentError)
end
end
- should 'return a url that starts with the auth_url' do
+ it 'should return a url that starts with the auth_url' do
@auth.zendesk_remote_auth_url(@valid_params)
end
- should 'have an empty hash param if external_id not provided' do
+ it 'should have an empty hash param if external_id not provided' do
@auth.zendesk_remote_auth_url(@valid_params).should =~ /hash=(&|$)/
end
- should 'have a hash param if external_id provided' do
+ it 'should have a hash param if external_id provided' do
@auth.zendesk_remote_auth_url(@valid_params.merge(:external_id => 'id')).should_not =~ /hash=(&|$)/
end
- should 'have a different hash param if external_id and remote_photo_url provided ' do
+ it 'should have a different hash param if external_id and remote_photo_url provided ' do
a=@auth.zendesk_remote_auth_url(@valid_params.merge(:external_id => 'id')).match(/(hash=[^&]*)/)[1]
b=@auth.zendesk_remote_auth_url(@valid_params.merge(:external_id => 'id', :remote_photo_url => 'photo_url')).match(/(hash=[^&]*)/)[1]
a.should_not == b
end
context 'given a user object' do
- setup do
+ before(:each) do
@user = mock
- @user.expects(:name).returns('a_name')
- @user.expects(:email).returns('an_email')
+ @user.should_receive(:name).and_return('a_name')
+ @user.should_receive(:email).and_return('an_email')
end
- should 'pull the name from the user' do
+ it 'should pull the name from the user' do
@auth.zendesk_remote_auth_url(@user).should =~ /name=a_name/
end
- should 'pull the email from the user' do
+ it 'should pull the email from the user' do
@auth.zendesk_remote_auth_url(@user).should =~ /email=an_email/
end
- should 'pull the id from the user' do
- @user.expects(:id).returns('an_id')
+ it 'should pull the id from the user' do
+ @user.should_receive(:id).and_return('an_id')
@auth.zendesk_remote_auth_url(@user).should =~ /external_id=an_id/
end
- should 'pull the organization from the user if available' do
- @user.expects(:zendesk_organization).returns('org')
+ it 'should pull the organization from the user if available' do
+ @user.should_receive(:zendesk_organization).and_return('org')
@auth.zendesk_remote_auth_url(@user).should =~ /organization=org/
end
Please sign in to comment.
Something went wrong with that request. Please try again.