Skip to content
This repository
Browse code

add a real test helper and ghetto mocks

  • Loading branch information...
commit 2e8313a2ee4fa09fdb3c507f8e29a28c770d970d 1 parent 2948365
Corey Donohoe authored
31 lib/sinatra/auth/github/test/test_helper.rb
... ... @@ -0,0 +1,31 @@
  1 +require 'warden/test/helpers'
  2 +require 'warden-github/user'
  3 +
  4 +module Sinatra
  5 + module Auth
  6 + module Github
  7 + module Test
  8 + module Helper
  9 + include(Warden::Test::Helpers)
  10 + def make_user(attrs = {})
  11 + User.make(attrs)
  12 + end
  13 +
  14 + class User < Warden::Github::Oauth::User
  15 + def self.make(attrs = {})
  16 + default_attrs = {
  17 + 'login' => "test_user",
  18 + 'name' => "Test User",
  19 + 'email' => "test@example.com",
  20 + 'company' => "GitHub",
  21 + 'gravatar_id' => 'https://a249.e.akamai.net/assets.github.com/images/gravatars/gravatar-140.png'
  22 + }
  23 + default_attrs.merge! attrs
  24 + User.new(default_attrs)
  25 + end
  26 + end
  27 + end
  28 + end
  29 + end
  30 + end
  31 +end
6 spec/login_spec.rb
@@ -2,13 +2,11 @@
2 2
3 3 describe "Logged in users" do
4 4 before do
5   - @user = User.make('login' => 'defunkt')
6   - sign_in @user
  5 + @user = make_user('login' => 'defunkt')
  6 + login_as @user
7 7 end
8 8
9 9 it "greets the user" do
10   - sign_in @user
11   -
12 10 get "/"
13 11 last_response.body.should eql("Hello there, defunkt!")
14 12 end
30 spec/spec_helper.rb
... ... @@ -1,39 +1,21 @@
1 1 require "bundler/setup"
2 2
3   -require File.join(File.dirname(__FILE__), '..', 'lib', 'sinatra', 'auth', 'github')
  3 +$:.push File.join(File.dirname(__FILE__), '..', 'lib')
4 4
5 5 require 'pp'
6 6 require 'rack/test'
7 7 require 'ruby-debug'
8   -require 'app'
9   -
10   -require 'warden-github/user'
11   -require 'warden/test/helpers'
12 8
13   -class User < Warden::Github::Oauth::User
14   - def self.make(attrs = {})
15   - default_attrs = {
16   - 'login' => "test_user",
17   - 'name' => "Test User",
18   - 'email' => "test@example.com",
19   - 'company' => "GitHub",
20   - 'gravatar_id' => 'https://a249.e.akamai.net/assets.github.com/images/gravatars/gravatar-140.png'
21   - }
22   - default_attrs.merge! attrs
23   - User.new(default_attrs)
24   - end
25   -end
  9 +require 'sinatra/auth/github'
  10 +require 'sinatra/auth/github/test/test_helper'
26 11
  12 +require 'app'
27 13
28 14 Spec::Runner.configure do |config|
29 15 config.include(Rack::Test::Methods)
30   - config.include(Warden::Test::Helpers)
31   -
32   - def sign_in(user)
33   - login_as(user)
34   - end
  16 + config.include(Sinatra::Auth::Github::Test::Helper)
35 17
36 18 def app
37   - run Example::App
  19 + Example::App
38 20 end
39 21 end

0 comments on commit 2e8313a

Please sign in to comment.
Something went wrong with that request. Please try again.