dchelimsky-rspec-rails 1.1.12 → 1.1.99.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/History.txt +29 -2
  2. data/License.txt +1 -1
  3. data/Manifest.txt +7 -6
  4. data/README.txt +5 -4
  5. data/Rakefile +14 -2
  6. data/TODO.txt +1 -0
  7. data/Upgrade.txt +30 -0
  8. data/generators/rspec/templates/rspec.rake +12 -10
  9. data/generators/rspec/templates/script/spec_server +10 -111
  10. data/generators/rspec_controller/rspec_controller_generator.rb +1 -5
  11. data/generators/rspec_scaffold/rspec_scaffold_generator.rb +9 -13
  12. data/generators/rspec_scaffold/templates/controller_spec.rb +25 -25
  13. data/generators/rspec_scaffold/templates/edit_erb_spec.rb +1 -1
  14. data/generators/rspec_scaffold/templates/helper_spec.rb +1 -1
  15. data/generators/rspec_scaffold/templates/index_erb_spec.rb +1 -1
  16. data/generators/rspec_scaffold/templates/new_erb_spec.rb +1 -1
  17. data/generators/rspec_scaffold/templates/routing_spec.rb +24 -20
  18. data/generators/rspec_scaffold/templates/show_erb_spec.rb +1 -1
  19. data/lib/spec/rails/example/controller_example_group.rb +46 -16
  20. data/lib/spec/rails/example/functional_example_group.rb +7 -22
  21. data/lib/spec/rails/example/helper_example_group.rb +6 -9
  22. data/lib/spec/rails/example/model_example_group.rb +1 -1
  23. data/lib/spec/rails/example/render_observer.rb +0 -26
  24. data/lib/spec/rails/example/view_example_group.rb +32 -34
  25. data/lib/spec/rails/example.rb +0 -2
  26. data/lib/spec/rails/extensions/active_support/test_case.rb +7 -0
  27. data/lib/spec/rails/extensions/spec/runner/configuration.rb +12 -44
  28. data/lib/spec/rails/extensions.rb +1 -1
  29. data/lib/spec/rails/matchers/ar_be_valid.rb +3 -0
  30. data/lib/spec/rails/matchers/have_text.rb +1 -1
  31. data/lib/spec/rails/matchers/include_text.rb +2 -2
  32. data/lib/spec/rails/matchers/redirect_to.rb +6 -14
  33. data/lib/spec/rails/matchers/render_template.rb +5 -1
  34. data/lib/spec/rails/spec_server.rb +86 -0
  35. data/lib/spec/rails/version.rb +2 -2
  36. data/lib/spec/rails.rb +10 -9
  37. data/rspec-rails.gemspec +12 -9
  38. data/spec/resources/controllers/controller_spec_controller.rb +1 -1
  39. data/spec/resources/controllers/render_spec_controller.rb +1 -1
  40. data/spec/resources/controllers/rjs_spec_controller.rb +1 -1
  41. data/spec/spec/rails/example/configuration_spec.rb +15 -29
  42. data/spec/spec/rails/example/{controller_spec_spec.rb → controller_example_group_spec.rb} +84 -60
  43. data/spec/spec/rails/example/cookies_proxy_spec.rb +32 -36
  44. data/spec/spec/rails/example/example_group_factory_spec.rb +5 -5
  45. data/spec/spec/rails/example/{helper_spec_spec.rb → helper_example_group_spec.rb} +8 -2
  46. data/spec/spec/rails/example/{model_spec_spec.rb → model_example_group_spec.rb} +3 -1
  47. data/spec/spec/rails/example/{view_spec_spec.rb → view_example_group_spec.rb} +33 -15
  48. data/spec/spec/rails/matchers/ar_be_valid_spec.rb +10 -0
  49. data/spec/spec/rails/matchers/assert_select_spec.rb +1 -0
  50. data/spec/spec/rails/matchers/have_text_spec.rb +12 -4
  51. data/spec/spec/rails/matchers/include_text_spec.rb +11 -13
  52. data/spec/spec/rails/matchers/redirect_to_spec.rb +221 -210
  53. data/spec/spec/rails/matchers/render_template_spec.rb +161 -158
  54. data/spec/spec/rails/spec_server_spec.rb +18 -7
  55. data/spec/spec_helper.rb +20 -9
  56. metadata +21 -10
  57. data/lib/spec/rails/example/rails_example_group.rb +0 -28
  58. data/lib/spec/rails/extensions/action_controller/base.rb +0 -14
@@ -16,29 +16,27 @@ module Spec
16
16
  describe "with a String key" do
17
17
 
18
18
  it "should accept a String value" do
19
- cookies = CookiesProxy.new(self)
20
- cookies['key'] = 'value'
19
+ proxy = CookiesProxy.new(self)
20
+ proxy['key'] = 'value'
21
21
  get :index
22
22
  if ::Rails::VERSION::STRING >= "2.3"
23
- cookies['key'].should == 'value'
23
+ proxy['key'].should == 'value'
24
24
  else
25
- cookies['key'].should == ['value']
25
+ proxy['key'].should == ['value']
26
26
  end
27
27
  end
28
28
 
29
- if ::Rails::VERSION::STRING >= "2.0.0"
30
- it "should accept a Hash value" do
31
- cookies = CookiesProxy.new(self)
32
- cookies['key'] = { :value => 'value', :expires => expiration = 1.hour.from_now, :path => path = '/path' }
33
- get :index
34
- if ::Rails::VERSION::STRING >= "2.3"
35
- cookies['key'].should == 'value'
36
- else
37
- cookies['key'].should == ['value']
38
- cookies['key'].value.should == ['value']
39
- cookies['key'].expires.should == expiration
40
- cookies['key'].path.should == path
41
- end
29
+ it "should accept a Hash value" do
30
+ proxy = CookiesProxy.new(self)
31
+ proxy['key'] = { :value => 'value', :expires => expiration = 1.hour.from_now, :path => path = '/path' }
32
+ get :index
33
+ if ::Rails::VERSION::STRING >= "2.3"
34
+ proxy['key'].should == 'value'
35
+ else
36
+ proxy['key'].should == ['value']
37
+ proxy['key'].value.should == ['value']
38
+ proxy['key'].expires.should == expiration
39
+ proxy['key'].path.should == path
42
40
  end
43
41
  end
44
42
 
@@ -47,29 +45,27 @@ module Spec
47
45
  describe "with a Symbol key" do
48
46
 
49
47
  it "should accept a String value" do
50
- example_cookies = CookiesProxy.new(self)
51
- example_cookies[:key] = 'value'
48
+ proxy = CookiesProxy.new(self)
49
+ proxy[:key] = 'value'
52
50
  get :index
53
51
  if ::Rails::VERSION::STRING >= "2.3"
54
- example_cookies[:key].should == 'value'
52
+ proxy[:key].should == 'value'
55
53
  else
56
- example_cookies[:key].should == ['value']
54
+ proxy[:key].should == ['value']
57
55
  end
58
56
  end
59
57
 
60
- if ::Rails::VERSION::STRING >= "2.0.0"
61
- it "should accept a Hash value" do
62
- example_cookies = CookiesProxy.new(self)
63
- example_cookies[:key] = { :value => 'value', :expires => expiration = 1.hour.from_now, :path => path = '/path' }
64
- get :index
65
- if ::Rails::VERSION::STRING >= "2.3"
66
- example_cookies[:key].should == 'value'
67
- else
68
- example_cookies[:key].should == ['value']
69
- example_cookies[:key].value.should == ['value']
70
- example_cookies[:key].expires.should == expiration
71
- example_cookies[:key].path.should == path
72
- end
58
+ it "should accept a Hash value" do
59
+ proxy = CookiesProxy.new(self)
60
+ proxy[:key] = { :value => 'value', :expires => expiration = 1.hour.from_now, :path => path = '/path' }
61
+ get :index
62
+ if ::Rails::VERSION::STRING >= "2.3"
63
+ proxy[:key].should == 'value'
64
+ else
65
+ proxy[:key].should == ['value']
66
+ proxy[:key].value.should == ['value']
67
+ proxy[:key].expires.should == expiration
68
+ proxy[:key].path.should == path
73
69
  end
74
70
  end
75
71
 
@@ -77,11 +73,11 @@ module Spec
77
73
 
78
74
  describe "#delete" do
79
75
  it "should delete from the response cookies" do
80
- example_cookies = CookiesProxy.new(self)
76
+ proxy = CookiesProxy.new(self)
81
77
  response_cookies = mock('cookies')
82
78
  response.should_receive(:cookies).and_return(response_cookies)
83
79
  response_cookies.should_receive(:delete).with('key')
84
- example_cookies.delete :key
80
+ proxy.delete :key
85
81
  end
86
82
  end
87
83
  end
@@ -24,21 +24,21 @@ module Spec
24
24
  example_group.superclass.should == Spec::Rails::Example::ModelExampleGroup
25
25
  end
26
26
 
27
- it "should return a RailsExampleGroup when given :spec_path => '/blah/spec/foo/' (anything other than controllers, views and helpers)" do
27
+ it "should return an ActiveSupport::TestCase when given :spec_path => '/blah/spec/foo/' (anything other than controllers, views and helpers)" do
28
28
  example_group = Spec::Example::ExampleGroupFactory.create_example_group(
29
29
  "name", :spec_path => '/blah/spec/foo/blah.rb'
30
30
  ) {}
31
- example_group.superclass.should == Spec::Rails::Example::RailsExampleGroup
31
+ example_group.superclass.should == ActiveSupport::TestCase
32
32
  end
33
33
 
34
- it "should return a RailsExampleGroup when given :spec_path => '\\blah\\spec\\foo\\' (windows format) (anything other than controllers, views and helpers)" do
34
+ it "should return an ActiveSupport::TestCase when given :spec_path => '\\blah\\spec\\foo\\' (windows format) (anything other than controllers, views and helpers)" do
35
35
  example_group = Spec::Example::ExampleGroupFactory.create_example_group(
36
36
  "name", :spec_path => '\\blah\\spec\\foo\\blah.rb'
37
37
  ) {}
38
- example_group.superclass.should == Spec::Rails::Example::RailsExampleGroup
38
+ example_group.superclass.should == ActiveSupport::TestCase
39
39
  end
40
40
 
41
- it "should return a ViewExampleGroup when given :type => :model" do
41
+ it "should return a ViewExampleGroup when given :type => :view" do
42
42
  example_group = Spec::Example::ExampleGroupFactory.create_example_group(
43
43
  "name", :type => :view
44
44
  ) {}
@@ -16,6 +16,8 @@ module Spec
16
16
  describe HelperExampleGroup, :type => :helper do
17
17
  helper_name :explicit
18
18
 
19
+ accesses_configured_helper_methods
20
+
19
21
  it "DEPRECATED should have direct access to methods defined in helpers" do
20
22
  method_in_explicit_helper.should =~ /text from a method/
21
23
  end
@@ -112,8 +114,6 @@ module Spec
112
114
  ActionView::Helpers::TextHelper,
113
115
  ActionView::Helpers::UrlHelper
114
116
  ]
115
- helpers << ActionView::Helpers::PaginationHelper rescue nil #removed for 2.0
116
- helpers << ActionView::Helpers::JavaScriptMacrosHelper rescue nil #removed for 2.0
117
117
  helpers.each do |helper_module|
118
118
  it "should include #{helper_module}" do
119
119
  self.class.ancestors.should include(helper_module)
@@ -146,6 +146,12 @@ module Spec
146
146
 
147
147
  describe HelperExampleGroup, "using a helper that uses output_buffer inside helper", :type => :helper do
148
148
  helper_name :explicit
149
+
150
+ before(:each) do
151
+ if Rails::VERSION::STRING <= "2.1"
152
+ pending("need to get this new feature working against pre 2.2 versions of rails")
153
+ end
154
+ end
149
155
 
150
156
  it "should not raise an error" do
151
157
  lambda { method_using_output_buffer }.should_not raise_error
@@ -4,7 +4,9 @@ module Spec
4
4
  module Rails
5
5
  module Example
6
6
  describe ModelExampleGroup do
7
- it "should clear its name from the description" do
7
+ accesses_configured_helper_methods
8
+
9
+ it "clears its name from the description" do
8
10
  group = describe("foo", :type => :model) do
9
11
  $nested_group = describe("bar") do
10
12
  end
@@ -4,6 +4,8 @@ describe "A template with an implicit helper", :type => :view do
4
4
  before(:each) do
5
5
  render "view_spec/implicit_helper"
6
6
  end
7
+
8
+ accesses_configured_helper_methods
7
9
 
8
10
  it "should include the helper" do
9
11
  response.should have_tag('div', :content => "This is text from a method in the ViewSpecHelper")
@@ -95,7 +97,7 @@ describe "A template that includes a partial", :type => :view do
95
97
  template.verify_rendered
96
98
  rescue Spec::Mocks::MockExpectationError => e
97
99
  ensure
98
- e.backtrace.find{|line| line =~ /view_spec_spec\.rb\:92/}.should_not be_nil
100
+ e.backtrace.find{|line| line =~ /#{__FILE__}\:#{__LINE__ - 6}/}.should_not be_nil
99
101
  end
100
102
  end
101
103
 
@@ -112,7 +114,7 @@ describe "A template that includes a partial", :type => :view do
112
114
  template.verify_rendered
113
115
  rescue Spec::Mocks::MockExpectationError => e
114
116
  ensure
115
- e.backtrace.find{|line| line =~ /view_spec_spec\.rb\:109/}.should_not be_nil
117
+ e.backtrace.find{|line| line =~ /#{__FILE__}\:#{__LINE__ - 6}/}.should_not be_nil
116
118
  end
117
119
  end
118
120
 
@@ -149,18 +151,16 @@ describe "A view that includes a partial using :collection and :spacer_template"
149
151
 
150
152
  end
151
153
 
152
- if Rails::VERSION::MAJOR >= 2
153
- describe "A view that includes a partial using an array as partial_path", :type => :view do
154
- before(:each) do
155
- renderable_object = Object.new
156
- renderable_object.stub!(:name).and_return("Renderable Object")
157
- assigns[:array] = [renderable_object]
158
- end
154
+ describe "A view that includes a partial using an array as partial_path", :type => :view do
155
+ before(:each) do
156
+ renderable_object = Object.new
157
+ renderable_object.stub!(:name).and_return("Renderable Object")
158
+ assigns[:array] = [renderable_object]
159
+ end
159
160
 
160
- it "should render the array passed through to render_partial without modification" do
161
- render "view_spec/template_with_partial_with_array"
162
- response.body.should match(/^Renderable Object$/)
163
- end
161
+ it "should render the array passed through to render_partial without modification" do
162
+ render "view_spec/template_with_partial_with_array"
163
+ response.body.should match(/^Renderable Object$/)
164
164
  end
165
165
  end
166
166
 
@@ -179,6 +179,18 @@ describe "A view", :type => :view do
179
179
  render "view_spec/accessor"
180
180
  end
181
181
 
182
+ it "should use the template as the implicit subject" do
183
+ subject.should == template
184
+ end
185
+
186
+ describe "with a specified subject" do
187
+ subject { 'specified' }
188
+
189
+ it "should use the specified subject" do
190
+ subject.should == 'specified'
191
+ end
192
+ end
193
+
182
194
  it "should have access to session data" do
183
195
  response.should have_tag("div#session", "session")
184
196
  end
@@ -270,6 +282,12 @@ describe "setting path parameters", :type => :view do
270
282
  end
271
283
  end
272
284
 
285
+ describe "route helpers", :type => :view do
286
+ it "should be available before render is called" do
287
+ custom_route_path.should == '/custom_route'
288
+ end
289
+ end
290
+
273
291
  module Spec
274
292
  module Rails
275
293
  module Example
@@ -285,10 +303,10 @@ module Spec
285
303
 
286
304
  it "should clear ActionView::Base.base_view_path on teardown" do
287
305
  group = describe("base_view_path_cleared flag", :type => :view) {}
288
- example = group.it{}
306
+ example = group.new("example",{}) {}
289
307
 
290
308
  ActionView::Base.should_receive(:base_view_path=).with(nil)
291
- group.run_after_each(example)
309
+ example.run_after_each
292
310
  end
293
311
  end
294
312
  end
@@ -13,6 +13,16 @@ describe "be_valid" do
13
13
  CanBeValid.new(false).should_not be_valid
14
14
  end
15
15
 
16
+ describe CanBeValid do
17
+ subject { CanBeValid.new(true) }
18
+ it { subject.should be_valid }
19
+ end
20
+
21
+ describe CanBeValid do
22
+ subject { CanBeValid.new(false) }
23
+ it { subject.should_not be_valid }
24
+ end
25
+
16
26
  class CanHaveErrors
17
27
  def initialize(errors)
18
28
  @valid = !errors
@@ -786,6 +786,7 @@ describe "have_tag", :type => :controller do
786
786
  end
787
787
 
788
788
  describe 'selecting in HTML that contains a mock with null_object' do
789
+ include ActionController::Assertions::SelectorAssertions
789
790
  module HTML
790
791
  class Document
791
792
  def initialize_with_strict_error_checking(text, strict=false, xml=false)
@@ -2,17 +2,25 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
2
2
 
3
3
  describe "have_text" do
4
4
 
5
+
6
+ it "should have a helpful description" do
7
+ matcher = have_text("foo bar")
8
+ matcher.description.should == 'have text "foo bar"'
9
+ end
10
+
5
11
  describe "where target is a Regexp" do
6
12
  it 'should should match submitted text using a regexp' do
7
- string = 'foo'
8
- string.should have_text(/fo*/)
13
+ matcher = have_text(/fo*/)
14
+ matcher.matches?('foo').should be_true
15
+ matcher.matches?('bar').should be_nil
9
16
  end
10
17
  end
11
18
 
12
19
  describe "where target is a String" do
13
20
  it 'should match submitted text using a string' do
14
- string = 'foo'
15
- string.should have_text('foo')
21
+ matcher = have_text('foo')
22
+ matcher.matches?('foo').should be_true
23
+ matcher.matches?('foo bar').should be_false
16
24
  end
17
25
  end
18
26
 
@@ -2,21 +2,19 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
2
2
 
3
3
  describe "include_text" do
4
4
 
5
- describe "where target is a String" do
6
- it 'should match submitted text using a string' do
7
- string = 'foo'
8
- string.should include_text('foo')
9
- end
5
+ it "should have a helpful description" do
6
+ matcher = include_text("foo bar")
7
+ matcher.description.should == 'include text "foo bar"'
8
+ end
10
9
 
11
- it 'should match if the text is contained' do
12
- string = 'I am a big piece of text'
13
- string.should include_text('big piece')
14
- end
10
+ it 'should match if the text is contained' do
11
+ matcher = include_text('big piece')
12
+ matcher.matches?('I am a big piece of text').should be_true
13
+ end
15
14
 
16
- it 'should not match if text is not contained' do
17
- string = 'I am a big piece of text'
18
- string.should_not include_text('corey')
19
- end
15
+ it 'should not match if text is not contained' do
16
+ matcher = include_text('foo bar')
17
+ matcher.matches?('hello world').should be_false
20
18
  end
21
19
 
22
20
  end