Fingertips-on-test-spec 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 2
3
- :patch: 0
4
2
  :major: 0
3
+ :minor: 2
4
+ :patch: 1
@@ -11,11 +11,24 @@ module Test
11
11
  # should.disallow.get :index
12
12
  def disallow
13
13
  Test::Spec::Rails::Macros::Authorization::TestGenerator.new(test_case,
14
- :access_denied?,
14
+ :access_denied?, true,
15
15
  'Expected access to be denied'
16
16
  )
17
17
  end
18
18
 
19
+ # Generates a test which tests authorization code. It assumes a method called <code>access_denied?</code>
20
+ # on the test case. The <code>access_denied?</code> method should return true when access is denied
21
+ # (ie. a 403 status code) and false in other cases.
22
+ #
23
+ # Example:
24
+ # should.allow.get :index
25
+ def allow
26
+ Test::Spec::Rails::Macros::Authorization::TestGenerator.new(test_case,
27
+ :access_denied?, false,
28
+ 'Expected access to be allowed'
29
+ )
30
+ end
31
+
19
32
  # Generates a test which tests authorization code. It assumes a method called <code>access_denied?</code>
20
33
  # on the test case. The <code>login_required?</code> method should return true when the visitor was
21
34
  # asked for credentials (ie. a 401 status code or a redirect to a login page) and false in other cases.
@@ -24,7 +37,7 @@ module Test
24
37
  # should.require_login.get :index
25
38
  def require_login
26
39
  Test::Spec::Rails::Macros::Authorization::TestGenerator.new(test_case,
27
- :login_required?,
40
+ :login_required?, true,
28
41
  'Expected login to be required'
29
42
  )
30
43
  end
@@ -32,10 +45,11 @@ module Test
32
45
 
33
46
  module Authorization
34
47
  class TestGenerator < Proxy
35
- attr_accessor :validation_method, :message
48
+ attr_accessor :validation_method, :message, :expected
36
49
 
37
- def initialize(test_case, validation_method, message)
50
+ def initialize(test_case, validation_method, expected, message)
38
51
  self.validation_method = validation_method
52
+ self.expected = expected
39
53
  self.message = message
40
54
 
41
55
  super(test_case)
@@ -47,11 +61,12 @@ module Test
47
61
  description << " #{params.inspect}" unless params.blank?
48
62
 
49
63
  validation_method = self.validation_method
64
+ expected = self.expected
50
65
  message = self.message
51
66
 
52
67
  test_case.it description do
53
68
  send(verb, action, immediate_values(params))
54
- send(validation_method).should.messaging(message) == true
69
+ send(validation_method).should.messaging(message) == expected
55
70
  end
56
71
  else
57
72
  super
data/on-test-spec.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{on-test-spec}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Manfred Stienstra", "Eloy Duran", "Cristi Balan"]
12
- s.date = %q{2009-09-11}
12
+ s.date = %q{2009-09-21}
13
13
  s.description = %q{Rails plugin to make testing Rails on test/spec easier.}
14
14
  s.email = %q{eloy.de.enige@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -43,10 +43,11 @@ Gem::Specification.new do |s|
43
43
  "test/share_test.rb",
44
44
  "test/test_helper.rb"
45
45
  ]
46
+ s.has_rdoc = true
46
47
  s.homepage = %q{http://github.com/Fingertips/on-test-spec}
47
48
  s.rdoc_options = ["--charset=UTF-8"]
48
49
  s.require_paths = ["lib"]
49
- s.rubygems_version = %q{1.3.5}
50
+ s.rubygems_version = %q{1.3.1}
50
51
  s.summary = %q{Rails plugin to make testing Rails on test/spec easier.}
51
52
  s.test_files = [
52
53
  "test/add_allow_switch_test.rb",
@@ -61,7 +62,7 @@ Gem::Specification.new do |s|
61
62
 
62
63
  if s.respond_to? :specification_version then
63
64
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
64
- s.specification_version = 3
65
+ s.specification_version = 2
65
66
 
66
67
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
67
68
  else
@@ -4,7 +4,7 @@ require 'test/spec/rails/macros'
4
4
  describe "TestGenerator, concerning generation" do
5
5
  before do
6
6
  @test = mock('Test')
7
- @generator = Test::Spec::Rails::Macros::Authorization::TestGenerator.new(@test, :access_denied?, 'Expected access to be denied')
7
+ @generator = Test::Spec::Rails::Macros::Authorization::TestGenerator.new(@test, :access_denied?, true, 'Expected access to be denied')
8
8
  end
9
9
 
10
10
  it "should generate a test description for a GET" do
@@ -32,7 +32,7 @@ end
32
32
 
33
33
  describe "TestGenerator, concerning test contents" do
34
34
  before do
35
- @generator = Test::Spec::Rails::Macros::Authorization::TestGenerator.new(Immediate, :access_denied?, 'Expected access to be denied')
35
+ @generator = Test::Spec::Rails::Macros::Authorization::TestGenerator.new(Immediate, :access_denied?, true, 'Expected access to be denied')
36
36
  @generator.stubs(:send).with(:access_denied?).returns(true)
37
37
  end
38
38
 
@@ -52,6 +52,16 @@ describe "TestGenerator, concerning test contents" do
52
52
 
53
53
  @generator.post(:create, params)
54
54
  end
55
+
56
+ it "should test the return value of the validation method against the expected method" do
57
+ @generator.expected = false
58
+ params = {:name => 'bitterzoet'}
59
+
60
+ @generator.expects(:immediate_values).with(params).returns(params)
61
+ @generator.stubs(:send).returns(false)
62
+
63
+ @generator.post(:create, params)
64
+ end
55
65
  end
56
66
 
57
67
  describe "Macros::Authorization" do
@@ -67,6 +77,17 @@ describe "Macros::Authorization" do
67
77
  generator.test_case.should == @test_case
68
78
  generator.validation_method.should == :access_denied?
69
79
  generator.message.should == 'Expected access to be denied'
80
+ generator.expected.should == true
81
+ end
82
+
83
+ it "should return a test generator when a new allow rule is invoked" do
84
+ generator = @proxy.allow
85
+
86
+ generator.should.is_a(Test::Spec::Rails::Macros::Authorization::TestGenerator)
87
+ generator.test_case.should == @test_case
88
+ generator.validation_method.should == :access_denied?
89
+ generator.message.should == 'Expected access to be denied'
90
+ generator.expected.should == false
70
91
  end
71
92
 
72
93
  it "should return a test generator when a new login_required rule is invoked" do
@@ -76,5 +97,6 @@ describe "Macros::Authorization" do
76
97
  generator.test_case.should == @test_case
77
98
  generator.validation_method.should == :login_required?
78
99
  generator.message.should == 'Expected login to be required'
100
+ generator.expected.should == true
79
101
  end
80
102
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Fingertips-on-test-spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manfred Stienstra
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-09-11 00:00:00 -07:00
14
+ date: 2009-09-21 00:00:00 -07:00
15
15
  default_executable:
16
16
  dependencies: []
17
17
 
@@ -50,7 +50,7 @@ files:
50
50
  - test/rails_test.rb
51
51
  - test/share_test.rb
52
52
  - test/test_helper.rb
53
- has_rdoc: false
53
+ has_rdoc: true
54
54
  homepage: http://github.com/Fingertips/on-test-spec
55
55
  licenses:
56
56
  post_install_message:
@@ -75,7 +75,7 @@ requirements: []
75
75
  rubyforge_project:
76
76
  rubygems_version: 1.3.5
77
77
  signing_key:
78
- specification_version: 3
78
+ specification_version: 2
79
79
  summary: Rails plugin to make testing Rails on test/spec easier.
80
80
  test_files:
81
81
  - test/add_allow_switch_test.rb