rspec-rails 2.0.0.beta.22 → 2.6.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.
Files changed (134) hide show
  1. data/.gitignore +10 -4
  2. data/.rspec +1 -0
  3. data/.travis.yml +10 -0
  4. data/History.md +1 -33
  5. data/License.txt +23 -0
  6. data/{README.markdown → README.md} +27 -7
  7. data/README_DEV.md +43 -0
  8. data/Rakefile +105 -35
  9. data/Thorfile +40 -0
  10. data/Upgrade.md +1 -0
  11. data/features/.nav +34 -0
  12. data/features/Autotest.md +24 -0
  13. data/features/Changelog.md +151 -0
  14. data/features/Generators.md +8 -0
  15. data/features/GettingStarted.md +84 -0
  16. data/features/README.md +58 -0
  17. data/features/Upgrade.md +117 -0
  18. data/features/controller_specs/README.md +45 -0
  19. data/features/controller_specs/anonymous_controller.feature +7 -7
  20. data/features/controller_specs/controller_spec.feature +18 -0
  21. data/features/controller_specs/isolation_from_views.feature +55 -8
  22. data/features/controller_specs/render_views.feature +63 -52
  23. data/features/helper_specs/helper_spec.feature +40 -6
  24. data/features/mailer_specs/url_helpers.feature +4 -4
  25. data/features/matchers/README.md +4 -0
  26. data/features/matchers/new_record_matcher.feature +6 -48
  27. data/features/matchers/redirect_to_matcher.feature +5 -6
  28. data/features/matchers/render_template_matcher.feature +13 -10
  29. data/features/mocks/mock_model.feature +29 -13
  30. data/features/mocks/stub_model.feature +4 -4
  31. data/features/model_specs/README.md +21 -0
  32. data/features/model_specs/errors_on.feature +2 -2
  33. data/features/model_specs/transactional_examples.feature +14 -9
  34. data/features/request_specs/request_spec.feature +49 -0
  35. data/features/routing_specs/README.md +17 -0
  36. data/features/{matchers → routing_specs}/be_routable_matcher.feature +25 -25
  37. data/features/routing_specs/named_routes.feature +18 -0
  38. data/features/routing_specs/route_to_matcher.feature +58 -0
  39. data/features/step_definitions/additional_cli_steps.rb +4 -0
  40. data/features/support/env.rb +14 -6
  41. data/features/view_specs/inferred_controller_path.feature +6 -6
  42. data/features/view_specs/stub_template.feature +51 -0
  43. data/features/view_specs/view_spec.feature +23 -42
  44. data/gemfiles/.bundle/config +2 -0
  45. data/gemfiles/base.rb +58 -0
  46. data/gemfiles/rails-3-0-stable +6 -0
  47. data/gemfiles/rails-3.0.0 +5 -0
  48. data/gemfiles/rails-3.0.1 +5 -0
  49. data/gemfiles/rails-3.0.2 +5 -0
  50. data/gemfiles/rails-3.0.3 +5 -0
  51. data/gemfiles/rails-3.0.4 +5 -0
  52. data/gemfiles/rails-3.0.5 +5 -0
  53. data/gemfiles/rails-3.0.6 +5 -0
  54. data/gemfiles/rails-3.0.7 +5 -0
  55. data/gemfiles/rails-3.1.0.beta1 +5 -0
  56. data/gemfiles/rails-master +7 -0
  57. data/lib/autotest/rails_rspec2.rb +1 -1
  58. data/lib/generators/rspec/controller/controller_generator.rb +4 -4
  59. data/lib/generators/rspec/helper/helper_generator.rb +3 -3
  60. data/lib/generators/rspec/install/install_generator.rb +0 -8
  61. data/lib/generators/rspec/integration/integration_generator.rb +15 -1
  62. data/lib/generators/rspec/integration/templates/request_spec.rb +7 -1
  63. data/lib/generators/rspec/mailer/mailer_generator.rb +2 -2
  64. data/lib/generators/rspec/model/model_generator.rb +1 -1
  65. data/lib/generators/rspec/observer/observer_generator.rb +1 -1
  66. data/lib/generators/rspec/scaffold/scaffold_generator.rb +40 -11
  67. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +90 -58
  68. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +15 -7
  69. data/lib/generators/rspec/scaffold/templates/index_spec.rb +7 -2
  70. data/lib/generators/rspec/scaffold/templates/new_spec.rb +14 -7
  71. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +14 -14
  72. data/lib/generators/rspec/scaffold/templates/show_spec.rb +7 -2
  73. data/lib/generators/rspec/view/view_generator.rb +1 -1
  74. data/lib/rspec/rails/example/controller_example_group.rb +25 -34
  75. data/lib/rspec/rails/example/helper_example_group.rb +5 -11
  76. data/lib/rspec/rails/example/mailer_example_group.rb +0 -14
  77. data/lib/rspec/rails/example/model_example_group.rb +0 -4
  78. data/lib/rspec/rails/example/rails_example_group.rb +0 -2
  79. data/lib/rspec/rails/example/request_example_group.rb +5 -30
  80. data/lib/rspec/rails/example/routing_example_group.rb +3 -5
  81. data/lib/rspec/rails/example/view_example_group.rb +20 -11
  82. data/lib/rspec/rails/example.rb +31 -1
  83. data/lib/rspec/rails/extensions/active_record/base.rb +28 -32
  84. data/lib/rspec/rails/fixture_support.rb +1 -1
  85. data/lib/rspec/rails/matchers/be_new_record.rb +5 -0
  86. data/lib/rspec/rails/matchers/redirect_to.rb +6 -2
  87. data/lib/rspec/rails/matchers/render_template.rb +5 -1
  88. data/lib/rspec/rails/matchers/routing_matchers.rb +24 -3
  89. data/lib/rspec/rails/matchers.rb +1 -1
  90. data/lib/rspec/rails/mocks.rb +118 -79
  91. data/lib/rspec/rails/module_inclusion.rb +17 -0
  92. data/lib/rspec/rails/tasks/rspec.rake +1 -1
  93. data/lib/rspec/rails/vendor/capybara.rb +29 -0
  94. data/lib/rspec/rails/vendor/webrat.rb +33 -0
  95. data/lib/rspec/rails/version.rb +1 -1
  96. data/lib/rspec/rails/view_assigns.rb +23 -4
  97. data/lib/rspec/rails/view_rendering.rb +50 -13
  98. data/lib/rspec/rails.rb +7 -10
  99. data/lib/rspec-rails.rb +4 -2
  100. data/rspec-rails.gemspec +11 -39
  101. data/spec/autotest/rails_rspec2_spec.rb +25 -14
  102. data/spec/rspec/rails/configuration_spec.rb +26 -0
  103. data/spec/rspec/rails/deprecations_spec.rb +18 -0
  104. data/spec/rspec/rails/example/controller_example_group_spec.rb +47 -5
  105. data/spec/rspec/rails/example/helper_example_group_spec.rb +19 -1
  106. data/spec/rspec/rails/example/request_example_group_spec.rb +2 -0
  107. data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +23 -0
  108. data/spec/rspec/rails/extensions/active_record/records_spec.rb +9 -0
  109. data/spec/rspec/rails/matchers/be_new_record_spec.rb +17 -0
  110. data/spec/rspec/rails/matchers/be_routable_spec.rb +41 -0
  111. data/spec/rspec/rails/matchers/redirect_to_spec.rb +67 -8
  112. data/spec/rspec/rails/matchers/render_template_spec.rb +67 -10
  113. data/spec/rspec/rails/matchers/route_to_spec.rb +77 -31
  114. data/spec/rspec/rails/mocks/ar_classes.rb +17 -25
  115. data/spec/rspec/rails/mocks/mock_model_spec.rb +50 -13
  116. data/spec/rspec/rails/mocks/stub_model_spec.rb +121 -67
  117. data/spec/rspec/rails/view_rendering_spec.rb +105 -0
  118. data/spec/spec_helper.rb +0 -22
  119. data/spec/support/matchers.rb +9 -0
  120. data/templates/generate_stuff.rb +10 -2
  121. data/templates/run_specs.rb +2 -2
  122. metadata +141 -79
  123. data/Gemfile +0 -24
  124. data/Gotchas.markdown +0 -14
  125. data/Upgrade.markdown +0 -31
  126. data/autotest/discover.rb +0 -1
  127. data/features/README.markdown +0 -12
  128. data/features/controller_specs/readers.feature +0 -18
  129. data/features/routing_specs/access_to_named_routes.feature +0 -15
  130. data/lib/generators/rspec/install/templates/autotest/discover.rb +0 -2
  131. data/lib/rspec/rails/browser_simulators.rb +0 -30
  132. data/spec/rspec/rails/example/view_rendering_spec.rb +0 -110
  133. data/specs.watchr +0 -59
  134. data/templates/Gemfile +0 -18
@@ -1,20 +1,79 @@
1
1
  require "spec_helper"
2
- require "action_controller/test_case"
2
+ require "active_support/test_case"
3
3
 
4
4
  describe "redirect_to" do
5
5
  include RSpec::Rails::Matchers::RedirectTo
6
6
 
7
+ let(:response) { ActionController::TestResponse.new }
8
+
7
9
  it "delegates to assert_redirected_to" do
8
10
  self.should_receive(:assert_redirected_to).with("destination")
9
11
  "response".should redirect_to("destination")
10
12
  end
11
13
 
12
- it "uses failure message from assert_redirected_to" do
13
- self.stub!(:assert_redirected_to).and_raise(
14
- Test::Unit::AssertionFailedError.new("this message"))
15
- response = ActionController::TestResponse.new
16
- expect do
17
- response.should redirect_to("destination")
18
- end.to raise_error("this message")
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
19
78
  end
20
79
  end
@@ -2,15 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe "render_template" do
4
4
  include RSpec::Rails::Matchers::RenderTemplate
5
-
6
- it "uses failure message from render_template" do
7
- self.stub!(:assert_template).and_raise(
8
- Test::Unit::AssertionFailedError.new("this message"))
9
- response = ActionController::TestResponse.new
10
- expect do
11
- response.should render_template("destination")
12
- end.to raise_error("this message")
13
- end
5
+ let(:response) { ActionController::TestResponse.new }
14
6
 
15
7
  context "given a hash" do
16
8
  it "delegates to assert_template" do
@@ -32,5 +24,70 @@ describe "render_template" do
32
24
  "response".should render_template(:template_name, "this message")
33
25
  end
34
26
  end
35
- end
36
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
@@ -2,52 +2,98 @@ require "spec_helper"
2
2
 
3
3
  describe "route_to" do
4
4
  include RSpec::Rails::Matchers::RoutingMatchers
5
+ include RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
5
6
 
6
- it "uses failure message from assert_routing" do
7
- self.stub!(:assert_routing).and_raise(
8
- Test::Unit::AssertionFailedError.new("this message"))
9
- expect do
10
- {"this" => "path"}.should route_to("these" => "options")
11
- end.to raise_error("this message")
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")
12
10
  end
13
- end
14
11
 
15
- describe "be_routable" do
16
- include RSpec::Rails::Matchers::RoutingMatchers
17
- attr_reader :routes
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
18
23
 
19
- before { @routes = double("routes") }
24
+ end
20
25
 
21
26
  context "with should" do
22
- it "passes if routes recognize the path" do
23
- routes.stub(:recognize_path) { {} }
24
- expect do
25
- {:get => "/a/path"}.should be_routable
26
- end.to_not raise_error
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
27
45
  end
28
46
 
29
- it "fails if routes do not recognize the path" do
30
- routes.stub(:recognize_path) { raise ActionController::RoutingError.new('ignore') }
31
- expect do
32
- {:get => "/a/path"}.should be_routable
33
- end.to raise_error(/expected \{:get=>"\/a\/path"\} to be routable/)
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
34
56
  end
35
57
  end
36
58
 
37
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
38
68
 
39
- it "passes if routes do not recognize the path" do
40
- routes.stub(:recognize_path) { raise ActionController::RoutingError.new('ignore') }
41
- expect do
42
- {:get => "/a/path"}.should_not be_routable
43
- end.to_not raise_error
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
44
78
  end
45
79
 
46
- it "fails if routes recognize the path" do
47
- routes.stub(:recognize_path) { {:controller => "foo"} }
48
- expect do
49
- {:get => "/a/path"}.should_not be_routable
50
- end.to raise_error(/expected \{:get=>"\/a\/path"\} not to be routable, but it routes to \{:controller=>"foo"\}/)
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
51
89
  end
52
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
53
98
  end
99
+
@@ -1,23 +1,26 @@
1
- module NoConnections
2
- def self.included(mod)
3
- (class << mod; self; end).class_eval do
4
- def columns
5
- []
6
- end
7
-
8
- def connection
9
- RSpec::Mocks::Mock.new.as_null_object
10
- end
11
- end
1
+ ActiveRecord::Base.establish_connection(
2
+ :adapter => 'sqlite3',
3
+ :database => ':memory:'
4
+ )
5
+
6
+ module Connections
7
+ def self.extended(host)
8
+
9
+ host.connection.execute <<-eosql
10
+ CREATE TABLE #{host.table_name} (
11
+ #{host.primary_key} integer PRIMARY KEY AUTOINCREMENT
12
+ )
13
+ eosql
12
14
  end
13
15
  end
14
16
 
15
17
  class NonActiveRecordModel
16
18
  extend ActiveModel::Naming
19
+ include ActiveModel::Conversion
17
20
  end
18
21
 
19
22
  class MockableModel < ActiveRecord::Base
20
- include NoConnections
23
+ extend Connections
21
24
  has_one :associated_model
22
25
  end
23
26
 
@@ -25,23 +28,12 @@ class SubMockableModel < MockableModel
25
28
  end
26
29
 
27
30
  class AssociatedModel < ActiveRecord::Base
28
- include NoConnections
31
+ extend Connections
29
32
  belongs_to :mockable_model
30
33
  end
31
34
 
32
35
  class AlternatePrimaryKeyModel < ActiveRecord::Base
33
- include NoConnections
34
36
  self.primary_key = :my_id
37
+ extend Connections
35
38
  attr_accessor :my_id
36
39
  end
37
-
38
- class ConnectableModel < ActiveRecord::Base
39
- establish_connection :adapter => 'sqlite3',
40
- :database => ':memory:'
41
-
42
- connection.execute <<-eosql
43
- CREATE TABLE connectable_models (
44
- id integer PRIMARY KEY AUTOINCREMENT
45
- )
46
- eosql
47
- end
@@ -41,19 +41,17 @@ describe "mock_model(RealModel)" do
41
41
  before(:each) do
42
42
  @model = mock_model(MockableModel, :id => 1)
43
43
  end
44
+
44
45
  it "is named using the stubbed id value" do
45
46
  @model.instance_variable_get(:@name).should == "MockableModel_1"
46
47
  end
47
- it "returns string of id value for to_param" do
48
- @model.to_param.should == "1"
49
- end
50
48
  end
51
49
 
52
50
  describe "destroy" do
53
- it "sets id to nil" do
51
+ it "sets persisted to false" do
54
52
  model = mock_model(MockableModel)
55
53
  model.destroy
56
- model.id.should be_nil
54
+ model.should_not be_persisted
57
55
  end
58
56
  end
59
57
 
@@ -146,11 +144,34 @@ describe "mock_model(RealModel)" do
146
144
  MockableModel.stub(:column_names).and_return(["column_a", "column_b"])
147
145
  @model = mock_model(MockableModel)
148
146
  end
149
- it "says it will respond_to?(key) if RealModel has the attribute 'key'" do
150
- @model.respond_to?("column_a").should be(true)
147
+
148
+ it "accepts two arguments" do
149
+ expect do
150
+ @model.respond_to?("title_before_type_cast", false)
151
+ end.to_not raise_exception
152
+ end
153
+
154
+ context "without as_null_object" do
155
+ it "says it will respond_to?(key) if RealModel has the attribute 'key'" do
156
+ @model.respond_to?("column_a").should be(true)
157
+ end
158
+ it "says it will not respond_to?(key) if RealModel does not have the attribute 'key'" do
159
+ @model.respond_to?("column_c").should be(false)
160
+ end
161
+ it "says it will not respond_to?(xxx_before_type_cast)" do
162
+ @model.respond_to?("title_before_type_cast").should be(false)
163
+ end
151
164
  end
152
- it "does not say it will respond_to?(key) if RealModel does not have the attribute 'key'" do
153
- @model.respond_to?("column_c").should be(false)
165
+ context "with as_null_object" do
166
+ it "says it will respond_to?(key) if RealModel has the attribute 'key'" do
167
+ @model.as_null_object.respond_to?("column_a").should be(true)
168
+ end
169
+ it "says it will respond_to?(key) even if RealModel does not have the attribute 'key'" do
170
+ @model.as_null_object.respond_to?("column_c").should be(true)
171
+ end
172
+ it "says it will not respond_to?(xxx_before_type_cast)" do
173
+ @model.as_null_object.respond_to?("title_before_type_cast").should be(false)
174
+ end
154
175
  end
155
176
  end
156
177
 
@@ -159,6 +180,12 @@ describe "mock_model(RealModel)" do
159
180
  model = NonActiveRecordModel.new
160
181
  model.should respond_to(:to_param)
161
182
  end
183
+ context "with as_null_object" do
184
+ it "says it will not respond_to?(xxx_before_type_cast)" do
185
+ model = NonActiveRecordModel.new.as_null_object
186
+ model.respond_to?("title_before_type_cast").should be(false)
187
+ end
188
+ end
162
189
  end
163
190
  end
164
191
 
@@ -181,26 +208,25 @@ describe "mock_model(RealModel)" do
181
208
  end
182
209
 
183
210
  describe "#persisted?" do
184
- context "with default id" do
211
+ context "with default identifier" do
185
212
  it "returns true" do
186
213
  mock_model(MockableModel).should be_persisted
187
214
  end
188
215
  end
189
216
 
190
- context "with explicit id" do
217
+ context "with explicit identifier via :id" do
191
218
  it "returns true" do
192
219
  mock_model(MockableModel, :id => 37).should be_persisted
193
220
  end
194
221
  end
195
222
 
196
- context "with id nil" do
223
+ context "with id => nil" do
197
224
  it "returns false" do
198
225
  mock_model(MockableModel, :id => nil).should_not be_persisted
199
226
  end
200
227
  end
201
228
  end
202
229
 
203
-
204
230
  describe "#valid?" do
205
231
  context "default" do
206
232
  it "returns true" do
@@ -220,6 +246,11 @@ describe "mock_model(RealModel)" do
220
246
  m.as_new_record.should be_new_record
221
247
  end
222
248
 
249
+ it "says it is not persisted" do
250
+ m = mock_model(MockableModel)
251
+ m.as_new_record.should_not be_persisted
252
+ end
253
+
223
254
  it "has a nil id" do
224
255
  mock_model(MockableModel).as_new_record.id.should be(nil)
225
256
  end
@@ -229,6 +260,12 @@ describe "mock_model(RealModel)" do
229
260
  end
230
261
  end
231
262
 
263
+ describe "#blank?" do
264
+ it "is false" do
265
+ mock_model(MockableModel).should_not be_blank
266
+ end
267
+ end
268
+
232
269
  describe "ActiveModel Lint tests" do
233
270
  require 'test/unit/assertions'
234
271
  require 'active_model/lint'