Class: Test::Spec::Rails::Macros::Should

Inherits:
Proxy
  • Object
show all
Defined in:
lib/test/spec/rails/macros.rb,
lib/test/spec/rails/macros/response.rb,
lib/test/spec/rails/macros/authorization.rb

Overview

Macros define methods on the Should class if they want to be called from the test case.

Instance Attribute Summary

Attributes inherited from Proxy

#test_case

Instance Method Summary collapse

Methods inherited from Proxy

#initialize

Constructor Details

This class inherits a constructor from Test::Spec::Rails::Macros::Proxy

Instance Method Details

#allowObject

Generates a test which tests authorization code. It assumes a method called access_denied? on the test case. The access_denied? method should return true when access is denied (ie. a 403 status code) and false in other cases.

Example:

should.allow.get :index

23
24
25
26
27
28
# File 'lib/test/spec/rails/macros/authorization.rb', line 23

def allow
  Test::Spec::Rails::Macros::Authorization::TestGenerator.new(test_case,
    :access_denied?, false,
    'Expected access to be allowed'
  )
end

#disallowObject

Generates a test which tests authorization code. It assumes a method called access_denied? on the test case. The access_denied? method should return true when access is denied (ie. a 403 status code) and false in other cases.

Example:

should.disallow.get :index

10
11
12
13
14
15
# File 'lib/test/spec/rails/macros/authorization.rb', line 10

def disallow
  Test::Spec::Rails::Macros::Authorization::TestGenerator.new(test_case,
    :access_denied?, true,
    'Expected access to be denied'
  )
end

#not_findObject


4
5
6
7
8
9
# File 'lib/test/spec/rails/macros/response.rb', line 4

def not_find
  Test::Spec::Rails::Macros::Response::TestGenerator.new(test_case,
    :not_found,
    'Expected to not find a resource'
  )
end

#require_loginObject

Generates a test which tests authorization code. It assumes a method called access_denied? on the test case. The login_required? method should return true when the visitor was asked for credentials (ie. a 401 status code or a redirect to a login page) and false in other cases.

Example:

should..get :index

36
37
38
39
40
41
# File 'lib/test/spec/rails/macros/authorization.rb', line 36

def 
  Test::Spec::Rails::Macros::Authorization::TestGenerator.new(test_case,
    :login_required?, true,
    'Expected login to be required'
  )
end