ammeter 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/ammeter.rb +8 -2
- data/lib/ammeter/init.rb +2 -0
- data/lib/ammeter/railtie.rb +7 -0
- data/lib/ammeter/rspec/generator/example.rb +1 -1
- data/lib/ammeter/rspec/generator/example/generator_example_group.rb +52 -48
- data/lib/ammeter/rspec/generator/{matcher.rb → matchers.rb} +0 -0
- data/lib/ammeter/version.rb +1 -1
- data/spec/{rspec → ammeter/rspec}/rails/generator/example/generator_example_group_spec.rb +2 -2
- data/spec/{rspec → ammeter/rspec}/rails/generator/matchers/be_a_migration_spec.rb +0 -0
- data/spec/{rspec → ammeter/rspec}/rails/generator/matchers/contain_spec.rb +1 -1
- data/spec/{rspec → ammeter/rspec}/rails/generator/matchers/exist_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +15 -27
- data/spec/rspec/rails/generator/matchers/be_a_new_spec.rb +0 -137
- data/spec/rspec/rails/generator/matchers/be_new_record_spec.rb +0 -17
- data/spec/rspec/rails/generator/matchers/be_routable_spec.rb +0 -41
- data/spec/rspec/rails/generator/matchers/errors_on_spec.rb +0 -38
- data/spec/rspec/rails/generator/matchers/redirect_to_spec.rb +0 -79
- data/spec/rspec/rails/generator/matchers/render_template_spec.rb +0 -93
- data/spec/rspec/rails/generator/matchers/route_to_spec.rb +0 -99
data/lib/ammeter.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
# Ensure that Rails has loaded & Initialized
|
4
|
+
if Rails::VERSION::STRING >= "3.1"
|
5
|
+
require 'ammeter/railtie'
|
6
|
+
else
|
7
|
+
require 'ammeter/init'
|
8
|
+
end
|
3
9
|
|
data/lib/ammeter/init.rb
ADDED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'ammeter/rspec/generator/example/generator_example_group'
|
2
2
|
|
3
3
|
RSpec::configure do |c|
|
4
|
-
c.include RSpec::Rails::GeneratorExampleGroup, :type => :generator, :example_group => {
|
4
|
+
c.include Ammeter::RSpec::Rails::GeneratorExampleGroup, :type => :generator, :example_group => {
|
5
5
|
:file_path => c.escaped_path(%w[spec generators])
|
6
6
|
}
|
7
7
|
end
|
@@ -1,61 +1,65 @@
|
|
1
1
|
require 'rails/generators'
|
2
2
|
require 'rspec/rails'
|
3
3
|
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
:prepare_destination, :destination_root, :current_path, :generator_class]
|
12
|
-
module ClassMethods
|
13
|
-
mattr_accessor :test_unit_test_case_delegate
|
14
|
-
delegate :default_arguments, :to => :'self.test_unit_test_case_delegate'
|
15
|
-
DELEGATED_METHODS.each do |method|
|
16
|
-
delegate method, :to => :'self.test_unit_test_case_delegate'
|
17
|
-
end
|
18
|
-
delegate :destination, :arguments, :to => :'self.test_unit_test_case_delegate.class'
|
4
|
+
module Ammeter
|
5
|
+
module RSpec
|
6
|
+
module Rails
|
7
|
+
# Delegates to Rails::Generators::TestCase to work with RSpec.
|
8
|
+
module GeneratorExampleGroup
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
include ::RSpec::Rails::RailsExampleGroup
|
19
11
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
12
|
+
DELEGATED_METHODS = [:generator, :destination_root_is_set?, :capture, :ensure_current_path,
|
13
|
+
:prepare_destination, :destination_root, :current_path, :generator_class]
|
14
|
+
module ClassMethods
|
15
|
+
mattr_accessor :test_unit_test_case_delegate
|
16
|
+
delegate :default_arguments, :to => :'self.test_unit_test_case_delegate'
|
17
|
+
DELEGATED_METHODS.each do |method|
|
18
|
+
delegate method, :to => :'self.test_unit_test_case_delegate'
|
19
|
+
end
|
20
|
+
delegate :destination, :arguments, :to => :'self.test_unit_test_case_delegate.class'
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
22
|
+
def initialize_delegate
|
23
|
+
self.test_unit_test_case_delegate = ::Rails::Generators::TestCase.new 'pending'
|
24
|
+
self.test_unit_test_case_delegate.class.tests(describes)
|
25
|
+
end
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
def run_generator(given_args=self.default_arguments, config={})
|
28
|
+
args, opts = Thor::Options.split(given_args)
|
29
|
+
capture(:stdout) { generator(args, opts, config).invoke_all }
|
30
|
+
end
|
31
|
+
end
|
36
32
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
initialize_delegate
|
33
|
+
module InstanceMethods
|
34
|
+
def invoke_task name
|
35
|
+
capture(:stdout) { generator.invoke_task(generator_class.all_tasks[name.to_s]) }
|
36
|
+
end
|
37
|
+
end
|
43
38
|
|
44
|
-
|
39
|
+
included do
|
40
|
+
delegate :run_generator, :destination, :arguments, :to => :'self.class'
|
41
|
+
DELEGATED_METHODS.each do |method|
|
42
|
+
delegate method, :to => :'self.class'
|
43
|
+
end
|
44
|
+
initialize_delegate
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
46
|
+
subject { generator }
|
47
|
+
|
48
|
+
before do
|
49
|
+
self.class.initialize_delegate
|
50
|
+
destination_root_is_set?
|
51
|
+
ensure_current_path
|
52
|
+
end
|
53
|
+
after do
|
54
|
+
ensure_current_path
|
55
|
+
end
|
56
|
+
metadata[:type] = :generator
|
57
|
+
end
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
+
def file relative
|
60
|
+
File.expand_path(relative, destination_root)
|
61
|
+
end
|
62
|
+
end
|
59
63
|
end
|
60
64
|
end
|
61
65
|
end
|
File without changes
|
data/lib/ammeter/version.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
module RSpec::Rails
|
3
|
+
module Ammeter::RSpec::Rails
|
4
4
|
describe GeneratorExampleGroup do
|
5
5
|
it { should be_included_in_files_in('./spec/generators/') }
|
6
6
|
it { should be_included_in_files_in('.\\spec\\generators\\') }
|
7
7
|
|
8
8
|
let(:group) do
|
9
|
-
RSpec::Core::ExampleGroup.describe do
|
9
|
+
::RSpec::Core::ExampleGroup.describe do
|
10
10
|
include GeneratorExampleGroup
|
11
11
|
end
|
12
12
|
end
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ammeter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.3
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alex Rothenberg
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06-
|
18
|
+
date: 2011-06-21 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -156,24 +156,19 @@ files:
|
|
156
156
|
- features/templates/rspec.rake
|
157
157
|
- lib/.DS_Store
|
158
158
|
- lib/ammeter.rb
|
159
|
+
- lib/ammeter/init.rb
|
160
|
+
- lib/ammeter/railtie.rb
|
159
161
|
- lib/ammeter/rspec/generator/example.rb
|
160
162
|
- lib/ammeter/rspec/generator/example/generator_example_group.rb
|
161
|
-
- lib/ammeter/rspec/generator/
|
163
|
+
- lib/ammeter/rspec/generator/matchers.rb
|
162
164
|
- lib/ammeter/rspec/generator/matchers/be_a_migration.rb
|
163
165
|
- lib/ammeter/rspec/generator/matchers/contain.rb
|
164
166
|
- lib/ammeter/rspec/generator/matchers/exist.rb
|
165
167
|
- lib/ammeter/version.rb
|
166
|
-
- spec/rspec/rails/generator/example/generator_example_group_spec.rb
|
167
|
-
- spec/rspec/rails/generator/matchers/be_a_migration_spec.rb
|
168
|
-
- spec/rspec/rails/generator/matchers/
|
169
|
-
- spec/rspec/rails/generator/matchers/
|
170
|
-
- spec/rspec/rails/generator/matchers/be_routable_spec.rb
|
171
|
-
- spec/rspec/rails/generator/matchers/contain_spec.rb
|
172
|
-
- spec/rspec/rails/generator/matchers/errors_on_spec.rb
|
173
|
-
- spec/rspec/rails/generator/matchers/exist_spec.rb
|
174
|
-
- spec/rspec/rails/generator/matchers/redirect_to_spec.rb
|
175
|
-
- spec/rspec/rails/generator/matchers/render_template_spec.rb
|
176
|
-
- spec/rspec/rails/generator/matchers/route_to_spec.rb
|
168
|
+
- spec/ammeter/rspec/rails/generator/example/generator_example_group_spec.rb
|
169
|
+
- spec/ammeter/rspec/rails/generator/matchers/be_a_migration_spec.rb
|
170
|
+
- spec/ammeter/rspec/rails/generator/matchers/contain_spec.rb
|
171
|
+
- spec/ammeter/rspec/rails/generator/matchers/exist_spec.rb
|
177
172
|
- spec/spec_helper.rb
|
178
173
|
- spec/support/helpers.rb
|
179
174
|
has_rdoc: true
|
@@ -215,16 +210,9 @@ test_files:
|
|
215
210
|
- features/support/env.rb
|
216
211
|
- features/templates/generate_example_app.rb
|
217
212
|
- features/templates/rspec.rake
|
218
|
-
- spec/rspec/rails/generator/example/generator_example_group_spec.rb
|
219
|
-
- spec/rspec/rails/generator/matchers/be_a_migration_spec.rb
|
220
|
-
- spec/rspec/rails/generator/matchers/
|
221
|
-
- spec/rspec/rails/generator/matchers/
|
222
|
-
- spec/rspec/rails/generator/matchers/be_routable_spec.rb
|
223
|
-
- spec/rspec/rails/generator/matchers/contain_spec.rb
|
224
|
-
- spec/rspec/rails/generator/matchers/errors_on_spec.rb
|
225
|
-
- spec/rspec/rails/generator/matchers/exist_spec.rb
|
226
|
-
- spec/rspec/rails/generator/matchers/redirect_to_spec.rb
|
227
|
-
- spec/rspec/rails/generator/matchers/render_template_spec.rb
|
228
|
-
- spec/rspec/rails/generator/matchers/route_to_spec.rb
|
213
|
+
- spec/ammeter/rspec/rails/generator/example/generator_example_group_spec.rb
|
214
|
+
- spec/ammeter/rspec/rails/generator/matchers/be_a_migration_spec.rb
|
215
|
+
- spec/ammeter/rspec/rails/generator/matchers/contain_spec.rb
|
216
|
+
- spec/ammeter/rspec/rails/generator/matchers/exist_spec.rb
|
229
217
|
- spec/spec_helper.rb
|
230
218
|
- spec/support/helpers.rb
|
@@ -1,137 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "be_a_new matcher" do
|
4
|
-
context "new record" do
|
5
|
-
let(:record) do
|
6
|
-
Class.new do
|
7
|
-
def new_record?; true; end
|
8
|
-
end.new
|
9
|
-
end
|
10
|
-
context "right class" do
|
11
|
-
it "passes" do
|
12
|
-
record.should be_a_new(record.class)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
context "wrong class" do
|
16
|
-
it "fails" do
|
17
|
-
record.should_not be_a_new(String)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context "existing record" do
|
23
|
-
let(:record) do
|
24
|
-
Class.new do
|
25
|
-
def new_record?; false; end
|
26
|
-
end.new
|
27
|
-
end
|
28
|
-
context "right class" do
|
29
|
-
it "fails" do
|
30
|
-
record.should_not be_a_new(record.class)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
context "wrong class" do
|
34
|
-
it "fails" do
|
35
|
-
record.should_not be_a_new(String)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "#with" do
|
41
|
-
context "right class and new record" do
|
42
|
-
let(:record) do
|
43
|
-
Class.new do
|
44
|
-
def initialize(attributes)
|
45
|
-
@attributes = attributes
|
46
|
-
end
|
47
|
-
|
48
|
-
def attributes
|
49
|
-
@attributes.stringify_keys
|
50
|
-
end
|
51
|
-
|
52
|
-
def new_record?; true; end
|
53
|
-
end.new(:foo => 'foo', :bar => 'bar')
|
54
|
-
end
|
55
|
-
|
56
|
-
context "all attributes same" do
|
57
|
-
it "passes" do
|
58
|
-
record.should be_a_new(record.class).with(:foo => 'foo', :bar => 'bar')
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "one attribute same" do
|
63
|
-
it "passes" do
|
64
|
-
record.should be_a_new(record.class).with(:foo => 'foo')
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context "no attributes same" do
|
69
|
-
it "fails" do
|
70
|
-
expect {
|
71
|
-
record.should be_a_new(record.class).with(:zoo => 'zoo', :car => 'car')
|
72
|
-
}.to raise_error(
|
73
|
-
%Q(attributes {"zoo"=>"zoo", "car"=>"car"} were not set on #{record.inspect})
|
74
|
-
)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context "one attribute value not the same" do
|
79
|
-
it "fails" do
|
80
|
-
expect {
|
81
|
-
record.should be_a_new(record.class).with(:foo => 'bar')
|
82
|
-
}.to raise_error(
|
83
|
-
%Q(attribute {"foo"=>"bar"} was not set on #{record.inspect})
|
84
|
-
)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context "wrong class and existing record" do
|
90
|
-
let(:record) do
|
91
|
-
Class.new do
|
92
|
-
def initialize(attributes)
|
93
|
-
@attributes = attributes
|
94
|
-
end
|
95
|
-
|
96
|
-
def attributes
|
97
|
-
@attributes.stringify_keys
|
98
|
-
end
|
99
|
-
|
100
|
-
def new_record?; false; end
|
101
|
-
end.new(:foo => 'foo', :bar => 'bar')
|
102
|
-
end
|
103
|
-
|
104
|
-
context "all attributes same" do
|
105
|
-
it "fails" do
|
106
|
-
expect {
|
107
|
-
record.should be_a_new(String).with(:foo => 'foo', :bar => 'bar')
|
108
|
-
}.to raise_error(
|
109
|
-
"expected #{record.inspect} to be a new String"
|
110
|
-
)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
context "no attributes same" do
|
115
|
-
it "fails" do
|
116
|
-
expect {
|
117
|
-
record.should be_a_new(String).with(:zoo => 'zoo', :car => 'car')
|
118
|
-
}.to raise_error(
|
119
|
-
"expected #{record.inspect} to be a new String and " +
|
120
|
-
%Q(attributes {"zoo"=>"zoo", "car"=>"car"} were not set on #{record.inspect})
|
121
|
-
)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context "one attribute value not the same" do
|
126
|
-
it "fails" do
|
127
|
-
expect {
|
128
|
-
record.should be_a_new(String).with(:foo => 'bar')
|
129
|
-
}.to raise_error(
|
130
|
-
"expected #{record.inspect} to be a new String and " +
|
131
|
-
%Q(attribute {"foo"=>"bar"} was not set on #{record.inspect})
|
132
|
-
)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "be_new_record" do
|
4
|
-
context "un-persisted record" do
|
5
|
-
it "passes" do
|
6
|
-
record = double('record', :persisted? => false)
|
7
|
-
record.should be_new_record
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
context "persisted record" do
|
12
|
-
it "fails" do
|
13
|
-
record = double('record', :persisted? => true)
|
14
|
-
record.should_not be_new_record
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "be_routable" do
|
4
|
-
include RSpec::Rails::Matchers::RoutingMatchers
|
5
|
-
attr_reader :routes
|
6
|
-
|
7
|
-
before { @routes = double("routes") }
|
8
|
-
|
9
|
-
context "with should" do
|
10
|
-
it "passes if routes recognize the path" do
|
11
|
-
routes.stub(:recognize_path) { {} }
|
12
|
-
expect do
|
13
|
-
{:get => "/a/path"}.should be_routable
|
14
|
-
end.to_not raise_error
|
15
|
-
end
|
16
|
-
|
17
|
-
it "fails if routes do not recognize the path" do
|
18
|
-
routes.stub(:recognize_path) { raise ActionController::RoutingError.new('ignore') }
|
19
|
-
expect do
|
20
|
-
{:get => "/a/path"}.should be_routable
|
21
|
-
end.to raise_error(/expected \{:get=>"\/a\/path"\} to be routable/)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "with should_not" do
|
26
|
-
|
27
|
-
it "passes if routes do not recognize the path" do
|
28
|
-
routes.stub(:recognize_path) { raise ActionController::RoutingError.new('ignore') }
|
29
|
-
expect do
|
30
|
-
{:get => "/a/path"}.should_not be_routable
|
31
|
-
end.to_not raise_error
|
32
|
-
end
|
33
|
-
|
34
|
-
it "fails if routes recognize the path" do
|
35
|
-
routes.stub(:recognize_path) { {:controller => "foo"} }
|
36
|
-
expect do
|
37
|
-
{:get => "/a/path"}.should_not be_routable
|
38
|
-
end.to raise_error(/expected \{:get=>"\/a\/path"\} not to be routable, but it routes to \{:controller=>"foo"\}/)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "error_on" do
|
4
|
-
it "provides a description including the name of what the error is on" do
|
5
|
-
have(1).error_on(:whatever).description.should == "have 1 error on :whatever"
|
6
|
-
end
|
7
|
-
|
8
|
-
it "provides a failure message including the number actually given" do
|
9
|
-
lambda {
|
10
|
-
[].should have(1).error_on(:whatever)
|
11
|
-
}.should raise_error("expected 1 error on :whatever, got 0")
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "errors_on" do
|
16
|
-
it "provides a description including the name of what the error is on" do
|
17
|
-
have(2).errors_on(:whatever).description.should == "have 2 errors on :whatever"
|
18
|
-
end
|
19
|
-
|
20
|
-
it "provides a failure message including the number actually given" do
|
21
|
-
lambda {
|
22
|
-
[1].should have(3).errors_on(:whatever)
|
23
|
-
}.should raise_error("expected 3 errors on :whatever, got 1")
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "have something other than error_on or errors_on" do
|
28
|
-
it "has a standard rspec failure message" do
|
29
|
-
lambda {
|
30
|
-
[1,2,3].should have(2).elements
|
31
|
-
}.should raise_error("expected 2 elements, got 3")
|
32
|
-
end
|
33
|
-
|
34
|
-
it "has a standard rspec description" do
|
35
|
-
have(2).elements.description.should == "have 2 elements"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "active_support/test_case"
|
3
|
-
|
4
|
-
describe "redirect_to" do
|
5
|
-
include RSpec::Rails::Matchers::RedirectTo
|
6
|
-
|
7
|
-
let(:response) { ActionController::TestResponse.new }
|
8
|
-
|
9
|
-
it "delegates to assert_redirected_to" do
|
10
|
-
self.should_receive(:assert_redirected_to).with("destination")
|
11
|
-
"response".should redirect_to("destination")
|
12
|
-
end
|
13
|
-
|
14
|
-
context "with should" do
|
15
|
-
context "when assert_redirected_to passes" do
|
16
|
-
it "passes" do
|
17
|
-
self.stub!(:assert_redirected_to)
|
18
|
-
expect do
|
19
|
-
response.should redirect_to("destination")
|
20
|
-
end.to_not raise_exception
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "when assert_redirected_to fails" do
|
25
|
-
it "uses failure message from assert_redirected_to" do
|
26
|
-
self.stub!(:assert_redirected_to) do
|
27
|
-
raise ActiveSupport::TestCase::Assertion.new("this message")
|
28
|
-
end
|
29
|
-
expect do
|
30
|
-
response.should redirect_to("destination")
|
31
|
-
end.to raise_error("this message")
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when fails due to some other exception" do
|
36
|
-
it "raises that exception" do
|
37
|
-
self.stub!(:assert_redirected_to) do
|
38
|
-
raise "oops"
|
39
|
-
end
|
40
|
-
expect do
|
41
|
-
response.should redirect_to("destination")
|
42
|
-
end.to raise_exception("oops")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "with should_not" do
|
48
|
-
context "when assert_redirected_to fails" do
|
49
|
-
it "passes" do
|
50
|
-
self.stub!(:assert_redirected_to) do
|
51
|
-
raise ActiveSupport::TestCase::Assertion.new("this message")
|
52
|
-
end
|
53
|
-
expect do
|
54
|
-
response.should_not redirect_to("destination")
|
55
|
-
end.to_not raise_exception
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context "when assert_redirected_to passes" do
|
60
|
-
it "fails with custom failure message" do
|
61
|
-
self.stub!(:assert_redirected_to)
|
62
|
-
expect do
|
63
|
-
response.should_not redirect_to("destination")
|
64
|
-
end.to raise_error(/expected not to redirect to \"destination\", but did/)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context "when fails due to some other exception" do
|
69
|
-
it "raises that exception" do
|
70
|
-
self.stub!(:assert_redirected_to) do
|
71
|
-
raise "oops"
|
72
|
-
end
|
73
|
-
expect do
|
74
|
-
response.should_not redirect_to("destination")
|
75
|
-
end.to raise_exception("oops")
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "render_template" do
|
4
|
-
include RSpec::Rails::Matchers::RenderTemplate
|
5
|
-
let(:response) { ActionController::TestResponse.new }
|
6
|
-
|
7
|
-
context "given a hash" do
|
8
|
-
it "delegates to assert_template" do
|
9
|
-
self.should_receive(:assert_template).with({:this => "hash"}, "this message")
|
10
|
-
"response".should render_template({:this => "hash"}, "this message")
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context "given a string" do
|
15
|
-
it "delegates to assert_template" do
|
16
|
-
self.should_receive(:assert_template).with("this string", "this message")
|
17
|
-
"response".should render_template("this string", "this message")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "given a symbol" do
|
22
|
-
it "converts to_s and delegates to assert_template" do
|
23
|
-
self.should_receive(:assert_template).with("template_name", "this message")
|
24
|
-
"response".should render_template(:template_name, "this message")
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "with should" do
|
29
|
-
context "when assert_template passes" do
|
30
|
-
it "passes" do
|
31
|
-
self.stub!(:assert_template)
|
32
|
-
expect do
|
33
|
-
response.should render_template("template_name")
|
34
|
-
end.to_not raise_exception
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context "when assert_template fails" do
|
39
|
-
it "uses failure message from assert_template" do
|
40
|
-
self.stub!(:assert_template) do
|
41
|
-
raise ActiveSupport::TestCase::Assertion.new("this message")
|
42
|
-
end
|
43
|
-
expect do
|
44
|
-
response.should render_template("template_name")
|
45
|
-
end.to raise_error("this message")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "when fails due to some other exception" do
|
50
|
-
it "raises that exception" do
|
51
|
-
self.stub!(:assert_template) do
|
52
|
-
raise "oops"
|
53
|
-
end
|
54
|
-
expect do
|
55
|
-
response.should render_template("template_name")
|
56
|
-
end.to raise_exception("oops")
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "with should_not" do
|
62
|
-
context "when assert_template fails" do
|
63
|
-
it "passes" do
|
64
|
-
self.stub!(:assert_template) do
|
65
|
-
raise ActiveSupport::TestCase::Assertion.new("this message")
|
66
|
-
end
|
67
|
-
expect do
|
68
|
-
response.should_not render_template("template_name")
|
69
|
-
end.to_not raise_exception
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context "when assert_template passes" do
|
74
|
-
it "fails with custom failure message" do
|
75
|
-
self.stub!(:assert_template)
|
76
|
-
expect do
|
77
|
-
response.should_not render_template("template_name")
|
78
|
-
end.to raise_error(/expected not to render \"template_name\", but did/)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context "when fails due to some other exception" do
|
83
|
-
it "raises that exception" do
|
84
|
-
self.stub!(:assert_template) do
|
85
|
-
raise "oops"
|
86
|
-
end
|
87
|
-
expect do
|
88
|
-
response.should_not render_template("template_name")
|
89
|
-
end.to raise_exception("oops")
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
@@ -1,99 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "route_to" do
|
4
|
-
include RSpec::Rails::Matchers::RoutingMatchers
|
5
|
-
include RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
|
6
|
-
|
7
|
-
it "delegates to assert_recognizes" do
|
8
|
-
self.should_receive(:assert_recognizes).with({ "these" => "options" }, { :method=> :get, :path=>"path" })
|
9
|
-
{:get => "path"}.should route_to("these" => "options")
|
10
|
-
end
|
11
|
-
|
12
|
-
context "with shortcut syntax" do
|
13
|
-
|
14
|
-
it "routes with extra options" do
|
15
|
-
self.should_receive(:assert_recognizes).with({ :controller => "controller", :action => "action", :extra => "options"}, { :method=> :get, :path=>"path" })
|
16
|
-
get("path").should route_to("controller#action", :extra => "options")
|
17
|
-
end
|
18
|
-
|
19
|
-
it "routes without extra options" do
|
20
|
-
self.should_receive(:assert_recognizes).with({ :controller => "controller", :action => "action"}, { :method=> :get, :path=>"path" })
|
21
|
-
get("path").should route_to("controller#action")
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
context "with should" do
|
27
|
-
context "when assert_recognizes passes" do
|
28
|
-
it "passes" do
|
29
|
-
self.stub!(:assert_recognizes)
|
30
|
-
expect do
|
31
|
-
{:get => "path"}.should route_to("these" => "options")
|
32
|
-
end.to_not raise_exception
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "when assert_recognizes fails" do
|
37
|
-
it "fails with message from assert_recognizes" do
|
38
|
-
self.stub!(:assert_recognizes) do
|
39
|
-
raise ActiveSupport::TestCase::Assertion.new("this message")
|
40
|
-
end
|
41
|
-
expect do
|
42
|
-
{:get => "path"}.should route_to("these" => "options")
|
43
|
-
end.to raise_error("this message")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "when an exception is raised" do
|
48
|
-
it "raises that exception" do
|
49
|
-
self.stub!(:assert_recognizes) do
|
50
|
-
raise "oops"
|
51
|
-
end
|
52
|
-
expect do
|
53
|
-
{:get => "path"}.should route_to("these" => "options")
|
54
|
-
end.to raise_exception("oops")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context "with should_not" do
|
60
|
-
context "when assert_recognizes passes" do
|
61
|
-
it "fails with custom message" do
|
62
|
-
self.stub!(:assert_recognizes)
|
63
|
-
expect do
|
64
|
-
{:get => "path"}.should_not route_to("these" => "options")
|
65
|
-
end.to raise_error(/expected .* not to route to .*/)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "when assert_recognizes fails" do
|
70
|
-
it "passes" do
|
71
|
-
self.stub!(:assert_recognizes) do
|
72
|
-
raise ActiveSupport::TestCase::Assertion.new("this message")
|
73
|
-
end
|
74
|
-
expect do
|
75
|
-
{:get => "path"}.should_not route_to("these" => "options")
|
76
|
-
end.to_not raise_error
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context "when an exception is raised" do
|
81
|
-
it "raises that exception" do
|
82
|
-
self.stub!(:assert_recognizes) do
|
83
|
-
raise "oops"
|
84
|
-
end
|
85
|
-
expect do
|
86
|
-
{:get => "path"}.should_not route_to("these" => "options")
|
87
|
-
end.to raise_exception("oops")
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
it "uses failure message from assert_recognizes" do
|
92
|
-
self.stub!(:assert_recognizes).and_raise(
|
93
|
-
ActiveSupport::TestCase::Assertion.new("this message"))
|
94
|
-
expect do
|
95
|
-
{"this" => "path"}.should route_to("these" => "options")
|
96
|
-
end.to raise_error("this message")
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|