on-test-spec 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/LICENSE +20 -0
- data/README +12 -0
- data/Rakefile +30 -0
- data/VERSION.yml +5 -0
- data/dot.autotest +93 -0
- data/lib/test/spec/add_allow_switch.rb +53 -0
- data/lib/test/spec/rails/controller_helpers.rb +11 -0
- data/lib/test/spec/rails/expectations.rb +192 -0
- data/lib/test/spec/rails/macros/authorization.rb +80 -0
- data/lib/test/spec/rails/macros/response.rb +57 -0
- data/lib/test/spec/rails/macros.rb +79 -0
- data/lib/test/spec/rails/request_helpers.rb +11 -0
- data/lib/test/spec/rails/response_helpers.rb +42 -0
- data/lib/test/spec/rails/spec_responder.rb +12 -0
- data/lib/test/spec/rails/test_spec_ext.rb +37 -0
- data/lib/test/spec/rails.rb +89 -0
- data/lib/test/spec/share.rb +48 -0
- data/on-test-spec.gemspec +74 -0
- data/test/add_allow_switch_test.rb +100 -0
- data/test/controller_helpers_test.rb +34 -0
- data/test/expectations_test.rb +459 -0
- data/test/macros/authorization_test.rb +102 -0
- data/test/macros/base_test.rb +78 -0
- data/test/macros/response_test.rb +82 -0
- data/test/rails_test.rb +100 -0
- data/test/share_test.rb +50 -0
- data/test/test_helper.rb +6 -0
- data/test/test_spec_ext_test.rb +26 -0
- metadata +95 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
require 'test/spec/rails/macros'
|
3
|
+
|
4
|
+
describe "Response::TestGenerator, concerning generation" do
|
5
|
+
before do
|
6
|
+
@test = mock('Test')
|
7
|
+
@generator = Test::Spec::Rails::Macros::Response::TestGenerator.new(@test, :not_found, 'Expected to not find a resource')
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should generate a test description for a GET" do
|
11
|
+
@test.expects(:it).with("should not find resource with GET on `index'")
|
12
|
+
@generator.get(:index)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should generate a test description for a POST with params" do
|
16
|
+
@test.expects(:it).with("should not find resource with POST on `create' {:venue=>{:name=>\"Bitterzoet\"}}")
|
17
|
+
@generator.post(:create, :venue => { :name => "Bitterzoet" })
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise a NoMethodError when you pass an unknown HTTP verb" do
|
21
|
+
lambda {
|
22
|
+
@generator.unknown :index
|
23
|
+
}.should.raise(NoMethodError)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
class Immediate
|
29
|
+
def self.it(description, &block)
|
30
|
+
block.call
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "Response::TestGenerator, concerning test contents" do
|
35
|
+
before do
|
36
|
+
@generator = Test::Spec::Rails::Macros::Response::TestGenerator.new(Immediate, :not_found, 'Expected to not find a resource')
|
37
|
+
@generator.stubs(:send).with(:status).returns(:not_found)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should send the verb and options to the controller" do
|
41
|
+
params = {:venue => {:name => "Bitterzoet"}}
|
42
|
+
@generator.stubs(:immediate_values).with(params).returns(params)
|
43
|
+
@generator.expects(:send).with(:post, :create, params)
|
44
|
+
|
45
|
+
@generator.post(:create, params)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should immediate values in params" do
|
49
|
+
params = {:name => 'bitterzoet'}
|
50
|
+
|
51
|
+
@generator.expects(:immediate_values).with(params).returns(params)
|
52
|
+
@generator.stubs(:send).returns(true)
|
53
|
+
|
54
|
+
@generator.post(:create, params)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should test the return value of the validation method against the expected method" do
|
58
|
+
@generator.expected = false
|
59
|
+
params = {:name => 'bitterzoet'}
|
60
|
+
|
61
|
+
@generator.expects(:immediate_values).with(params).returns(params)
|
62
|
+
@generator.stubs(:send).returns(false)
|
63
|
+
|
64
|
+
@generator.post(:create, params)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "Macros::Response" do
|
69
|
+
before do
|
70
|
+
@test_case = mock('TestCase')
|
71
|
+
@proxy = Test::Spec::Rails::Macros::Should.new(@test_case)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should return a test generator when a new not found rule is invoked" do
|
75
|
+
generator = @proxy.not_find
|
76
|
+
|
77
|
+
generator.should.is_a(Test::Spec::Rails::Macros::Response::TestGenerator)
|
78
|
+
generator.test_case.should == @test_case
|
79
|
+
generator.status.should == :not_found
|
80
|
+
generator.message.should == 'Expected to not find a resource'
|
81
|
+
end
|
82
|
+
end
|
data/test/rails_test.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require File.expand_path("../test_helper", __FILE__)
|
2
|
+
require "test/spec/rails"
|
3
|
+
|
4
|
+
class RegularClass; end
|
5
|
+
class ActiveRecordModel < ActiveRecord::Base; end
|
6
|
+
class ActionControllerClass < ActionController::Base; end
|
7
|
+
module ViewModuleHelper; end
|
8
|
+
|
9
|
+
CLASS_TO_TESTCASE_MAPPINGS = {
|
10
|
+
RegularClass => ActiveSupport::TestCase,
|
11
|
+
ActiveRecordModel => ActiveRecord::TestCase,
|
12
|
+
ActionControllerClass => ActionController::TestCase,
|
13
|
+
ViewModuleHelper => ActionView::TestCase
|
14
|
+
}
|
15
|
+
|
16
|
+
describe "A test case with a traditional, string only, description" do
|
17
|
+
test_case = self
|
18
|
+
|
19
|
+
it "should inherit from ActiveSupport::TestCase" do
|
20
|
+
test_case.superclass.should.be ActiveSupport::TestCase
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have the description given" do
|
24
|
+
test_case.name.should ==
|
25
|
+
"A test case with a traditional, string only, description"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "A test case for an", ActionControllerClass do
|
30
|
+
test_case = self
|
31
|
+
|
32
|
+
it "should have the class assigned as the class to test" do
|
33
|
+
test_case.controller_class.should.be ActionControllerClass
|
34
|
+
@controller.should.be.instance_of ActionControllerClass
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "A test case for a", ViewModuleHelper do
|
39
|
+
test_case = self
|
40
|
+
|
41
|
+
it "should have the module assigned as the module to test" do
|
42
|
+
test_case.helper_class.should.be ViewModuleHelper
|
43
|
+
test_case.ancestors.should.include ViewModuleHelper
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
CLASS_TO_TESTCASE_MAPPINGS.each do |test_class, expected_test_case|
|
48
|
+
|
49
|
+
describe test_class do
|
50
|
+
test_case = self
|
51
|
+
|
52
|
+
it "should inherit from #{expected_test_case}" do
|
53
|
+
test_case.superclass.should.be expected_test_case
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should use the model class name as the description" do
|
57
|
+
test_case.name.should == test_class.to_s
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "A test case with prepended description for", test_class do
|
62
|
+
test_case = self
|
63
|
+
|
64
|
+
it "should inherit from #{expected_test_case}" do
|
65
|
+
test_case.superclass.should.be expected_test_case
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should have appended the model class name to the description" do
|
69
|
+
test_case.name.should ==
|
70
|
+
"A test case with prepended description for #{test_class}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe test_class, "test case with a model class and an appended description" do
|
75
|
+
test_case = self
|
76
|
+
|
77
|
+
it "should inherit from #{expected_test_case}" do
|
78
|
+
test_case.superclass.should.be expected_test_case
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should have prepended the model class name to the description" do
|
82
|
+
test_case.name.should ==
|
83
|
+
"#{test_class} test case with a model class and an appended description"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "An", test_class, "test case with a model class and a prepended _and_ appended description" do
|
88
|
+
test_case = self
|
89
|
+
|
90
|
+
it "should inherit from #{expected_test_case}" do
|
91
|
+
test_case.superclass.should.be expected_test_case
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should have inserted the model class name in the middle of the description" do
|
95
|
+
test_case.name.should ==
|
96
|
+
"An #{test_class} test case with a model class and a prepended _and_ appended description"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
data/test/share_test.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
require 'test/spec/share'
|
3
|
+
|
4
|
+
class DummyMock
|
5
|
+
extend SharedSpecsInclusionHelper
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_reader :times_called
|
9
|
+
def it(name, &block)
|
10
|
+
@times_called ||= 0
|
11
|
+
@times_called += 1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
share "Dummy" do
|
17
|
+
it("spec 1") {}
|
18
|
+
it("spec 2") {}
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "Shared specs" do
|
22
|
+
it "should define a global variable that will hold all the shared specs" do
|
23
|
+
$shared_specs.should.be.instance_of Hash
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "Kernel#share" do
|
28
|
+
it "should add the shared specs to the global shared modules variable" do
|
29
|
+
before = $shared_specs.length
|
30
|
+
share("Bar") {}
|
31
|
+
$shared_specs.length.should == before + 1
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should have stored the proc that holds the specs" do
|
35
|
+
$shared_specs['Dummy'].should.be.instance_of Proc
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "SharedSpecsInclusionHelper::shared_specs_for" do
|
40
|
+
it "should have extended Test::Unit::TestCase" do
|
41
|
+
Test::Unit::TestCase.should.respond_to :shared_specs_for
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return the specified module containing the shared specs" do
|
45
|
+
DummyMock.class_eval do
|
46
|
+
shared_specs_for 'Dummy'
|
47
|
+
end
|
48
|
+
DummyMock.times_called.should.be 2
|
49
|
+
end
|
50
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module SomeIncludableAssertions
|
4
|
+
def assert_foo
|
5
|
+
assert true
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
ActionView::TestCase.send(:include, SomeIncludableAssertions)
|
10
|
+
|
11
|
+
module SomeIncludableExpectations
|
12
|
+
def foo
|
13
|
+
test_case.assert_foo
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Test::Spec::Should.send(:include, SomeIncludableExpectations)
|
18
|
+
|
19
|
+
module AViewHelper
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "Test::Spec::ExpectationExt, for", AViewHelper do
|
23
|
+
it "should call assert methods directly on the test case instance" do
|
24
|
+
lambda { Object.new.should.foo }.should.not.raise
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: on-test-spec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Manfred Stienstra
|
8
|
+
- Eloy Duran
|
9
|
+
- Cristi Balan
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2009-11-03 00:00:00 +01:00
|
15
|
+
default_executable:
|
16
|
+
dependencies: []
|
17
|
+
|
18
|
+
description: Rails plugin to make testing Rails on test/spec easier.
|
19
|
+
email: eloy.de.enige@gmail.com
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files:
|
25
|
+
- LICENSE
|
26
|
+
- README
|
27
|
+
files:
|
28
|
+
- .gitignore
|
29
|
+
- LICENSE
|
30
|
+
- README
|
31
|
+
- Rakefile
|
32
|
+
- VERSION.yml
|
33
|
+
- dot.autotest
|
34
|
+
- lib/test/spec/add_allow_switch.rb
|
35
|
+
- lib/test/spec/rails.rb
|
36
|
+
- lib/test/spec/rails/controller_helpers.rb
|
37
|
+
- lib/test/spec/rails/expectations.rb
|
38
|
+
- lib/test/spec/rails/macros.rb
|
39
|
+
- lib/test/spec/rails/macros/authorization.rb
|
40
|
+
- lib/test/spec/rails/macros/response.rb
|
41
|
+
- lib/test/spec/rails/request_helpers.rb
|
42
|
+
- lib/test/spec/rails/response_helpers.rb
|
43
|
+
- lib/test/spec/rails/spec_responder.rb
|
44
|
+
- lib/test/spec/rails/test_spec_ext.rb
|
45
|
+
- lib/test/spec/share.rb
|
46
|
+
- on-test-spec.gemspec
|
47
|
+
- test/add_allow_switch_test.rb
|
48
|
+
- test/controller_helpers_test.rb
|
49
|
+
- test/expectations_test.rb
|
50
|
+
- test/macros/authorization_test.rb
|
51
|
+
- test/macros/base_test.rb
|
52
|
+
- test/macros/response_test.rb
|
53
|
+
- test/rails_test.rb
|
54
|
+
- test/share_test.rb
|
55
|
+
- test/test_helper.rb
|
56
|
+
- test/test_spec_ext_test.rb
|
57
|
+
has_rdoc: true
|
58
|
+
homepage: http://github.com/Fingertips/on-test-spec
|
59
|
+
licenses: []
|
60
|
+
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --charset=UTF-8
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.3.5
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Rails plugin to make testing Rails on test/spec easier.
|
85
|
+
test_files:
|
86
|
+
- test/add_allow_switch_test.rb
|
87
|
+
- test/controller_helpers_test.rb
|
88
|
+
- test/expectations_test.rb
|
89
|
+
- test/macros/authorization_test.rb
|
90
|
+
- test/macros/base_test.rb
|
91
|
+
- test/macros/response_test.rb
|
92
|
+
- test/rails_test.rb
|
93
|
+
- test/share_test.rb
|
94
|
+
- test/test_helper.rb
|
95
|
+
- test/test_spec_ext_test.rb
|