rspec-rails 3.0.0.beta1 → 3.0.0.beta2

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 (75) hide show
  1. data.tar.gz.sig +0 -0
  2. data/Changelog.md +46 -0
  3. data/README.md +19 -17
  4. data/features/Generators.md +1 -0
  5. data/features/README.md +7 -15
  6. data/features/controller_specs/anonymous_controller.feature +222 -164
  7. data/lib/generators/rspec/feature/feature_generator.rb +15 -0
  8. data/lib/generators/rspec/feature/templates/feature_spec.rb +5 -0
  9. data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +0 -6
  10. data/lib/generators/rspec/integration/integration_generator.rb +0 -11
  11. data/lib/generators/rspec/integration/templates/request_spec.rb +0 -5
  12. data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
  13. data/lib/generators/rspec/scaffold/scaffold_generator.rb +0 -8
  14. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +4 -4
  15. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +0 -9
  16. data/lib/generators/rspec/scaffold/templates/index_spec.rb +0 -7
  17. data/lib/generators/rspec/scaffold/templates/new_spec.rb +0 -9
  18. data/lib/generators/rspec/scaffold/templates/show_spec.rb +0 -7
  19. data/lib/rspec/rails.rb +1 -1
  20. data/lib/rspec/rails/adapters.rb +18 -15
  21. data/lib/rspec/rails/example/controller_example_group.rb +18 -9
  22. data/lib/rspec/rails/example/view_example_group.rb +3 -0
  23. data/lib/rspec/rails/matchers/be_a_new.rb +1 -1
  24. data/lib/rspec/rails/matchers/be_new_record.rb +2 -2
  25. data/lib/rspec/rails/matchers/be_valid.rb +10 -3
  26. data/lib/rspec/rails/matchers/have_rendered.rb +2 -2
  27. data/lib/rspec/rails/matchers/redirect_to.rb +2 -2
  28. data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
  29. data/lib/rspec/rails/matchers/routing_matchers.rb +7 -3
  30. data/lib/rspec/rails/mocks.rb +50 -26
  31. data/lib/rspec/rails/vendor/capybara.rb +4 -4
  32. data/lib/rspec/rails/version.rb +1 -1
  33. data/spec/generators/rspec/controller/controller_generator_spec.rb +16 -16
  34. data/spec/generators/rspec/feature/feature_generator_spec.rb +43 -0
  35. data/spec/generators/rspec/helper/helper_generator_spec.rb +4 -4
  36. data/spec/generators/rspec/install/install_generator_spec.rb +4 -4
  37. data/spec/generators/rspec/integration/integration_generator_spec.rb +8 -20
  38. data/spec/generators/rspec/mailer/mailer_generator_spec.rb +11 -11
  39. data/spec/generators/rspec/model/model_generator_spec.rb +7 -7
  40. data/spec/generators/rspec/observer/observer_generator_spec.rb +3 -3
  41. data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +34 -34
  42. data/spec/generators/rspec/view/view_generator_spec.rb +6 -6
  43. data/spec/rspec/rails/assertion_adapter_spec.rb +3 -3
  44. data/spec/rspec/rails/configuration_spec.rb +2 -2
  45. data/spec/rspec/rails/deprecations_spec.rb +1 -1
  46. data/spec/rspec/rails/example/controller_example_group_spec.rb +79 -20
  47. data/spec/rspec/rails/example/feature_example_group_spec.rb +2 -2
  48. data/spec/rspec/rails/example/helper_example_group_spec.rb +12 -12
  49. data/spec/rspec/rails/example/mailer_example_group_spec.rb +3 -3
  50. data/spec/rspec/rails/example/model_example_group_spec.rb +3 -3
  51. data/spec/rspec/rails/example/request_example_group_spec.rb +5 -5
  52. data/spec/rspec/rails/example/routing_example_group_spec.rb +5 -5
  53. data/spec/rspec/rails/example/view_example_group_spec.rb +44 -29
  54. data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +3 -3
  55. data/spec/rspec/rails/fixture_support_spec.rb +3 -3
  56. data/spec/rspec/rails/matchers/be_a_new_spec.rb +17 -17
  57. data/spec/rspec/rails/matchers/be_new_record_spec.rb +2 -2
  58. data/spec/rspec/rails/matchers/be_routable_spec.rb +8 -8
  59. data/spec/rspec/rails/matchers/be_valid_spec.rb +33 -4
  60. data/spec/rspec/rails/matchers/has_spec.rb +1 -1
  61. data/spec/rspec/rails/matchers/have_rendered_spec.rb +3 -3
  62. data/spec/rspec/rails/matchers/redirect_to_spec.rb +7 -6
  63. data/spec/rspec/rails/matchers/relation_match_array_spec.rb +6 -6
  64. data/spec/rspec/rails/matchers/route_to_spec.rb +21 -21
  65. data/spec/rspec/rails/minitest_lifecycle_adapter_spec.rb +9 -0
  66. data/spec/rspec/rails/mocks/mock_model_spec.rb +95 -73
  67. data/spec/rspec/rails/mocks/stub_model_spec.rb +23 -23
  68. data/spec/rspec/rails/setup_and_teardown_adapter_spec.rb +4 -4
  69. data/spec/rspec/rails/view_rendering_spec.rb +14 -14
  70. data/spec/spec_helper.rb +3 -5
  71. data/spec/support/helpers.rb +15 -1
  72. metadata +112 -46
  73. metadata.gz.sig +0 -0
  74. checksums.yaml +0 -15
  75. checksums.yaml.gz.sig +0 -2
@@ -1,5 +1,4 @@
1
1
  require "spec_helper"
2
- require 'active_support/all'
3
2
  require 'rspec/rails/matchers/be_valid'
4
3
 
5
4
  describe "be_valid matcher" do
@@ -11,7 +10,25 @@ describe "be_valid matcher" do
11
10
  validates_presence_of :title
12
11
  end
13
12
 
13
+ class Book
14
+ def valid?
15
+ false
16
+ end
17
+
18
+ def errors
19
+ ['the spine is broken', 'the pages are dog-eared']
20
+ end
21
+ end
22
+
23
+ class Boat
24
+ def valid?
25
+ false
26
+ end
27
+ end
28
+
14
29
  let(:post) { Post.new }
30
+ let(:book) { Book.new }
31
+ let(:boat) { Boat.new }
15
32
 
16
33
  it "includes the error messages in the failure message" do
17
34
  expect {
@@ -19,8 +36,20 @@ describe "be_valid matcher" do
19
36
  }.to raise_exception(/Title can't be blank/)
20
37
  end
21
38
 
39
+ it "includes the error messages for simple implementations of error messages" do
40
+ expect {
41
+ expect(book).to be_valid
42
+ }.to raise_exception(/the spine is broken/)
43
+ end
44
+
45
+ it "includes a brief error message for the simplest implementation of validity" do
46
+ expect {
47
+ expect(boat).to be_valid
48
+ }.to raise_exception(/expected .+ to be valid\z/)
49
+ end
50
+
22
51
  it "includes a failure message for the negative case" do
23
- post.stub(:valid?) { true }
52
+ allow(post).to receive(:valid?) { true }
24
53
  expect {
25
54
  expect(post).not_to be_valid
26
55
  }.to raise_exception(/expected .* not to be valid/)
@@ -33,12 +62,12 @@ describe "be_valid matcher" do
33
62
  end
34
63
 
35
64
  it "includes the validation context if provided" do
36
- post.should_receive(:valid?).with(:create) { true }
65
+ expect(post).to receive(:valid?).with(:create) { true }
37
66
  expect(post).to be_valid(:create)
38
67
  end
39
68
 
40
69
  it "does not include the validation context if not provided" do
41
- post.should_receive(:valid?).with(no_args) { true }
70
+ expect(post).to receive(:valid?).with(no_args) { true }
42
71
  expect(post).to be_valid
43
72
  end
44
73
  end
@@ -24,6 +24,6 @@ end
24
24
  describe "should have_xxx" do
25
25
  it "works with ActiveRecord::Associations::CollectionProxy" do
26
26
  owner = CollectionOwner.new
27
- owner.associated_items.should have_some_quality
27
+ expect(owner.associated_items).to have_some_quality
28
28
  end
29
29
  end
@@ -7,21 +7,21 @@ require "spec_helper"
7
7
 
8
8
  context "given a hash" do
9
9
  it "delegates to assert_template" do
10
- self.should_receive(:assert_template).with({:this => "hash"}, "this message")
10
+ expect(self).to receive(:assert_template).with({:this => "hash"}, "this message")
11
11
  expect("response").to send(template_expectation, {:this => "hash"}, "this message")
12
12
  end
13
13
  end
14
14
 
15
15
  context "given a string" do
16
16
  it "delegates to assert_template" do
17
- self.should_receive(:assert_template).with("this string", "this message")
17
+ expect(self).to receive(:assert_template).with("this string", "this message")
18
18
  expect("response").to send(template_expectation, "this string", "this message")
19
19
  end
20
20
  end
21
21
 
22
22
  context "given a symbol" do
23
23
  it "converts to_s and delegates to assert_template" do
24
- self.should_receive(:assert_template).with("template_name", "this message")
24
+ expect(self).to receive(:assert_template).with("template_name", "this message")
25
25
  expect("response").to send(template_expectation, :template_name, "this message")
26
26
  end
27
27
  end
@@ -1,4 +1,5 @@
1
1
  require "spec_helper"
2
+ require "active_support"
2
3
  require "active_support/test_case"
3
4
 
4
5
  describe "redirect_to" do
@@ -12,7 +13,7 @@ describe "redirect_to" do
12
13
 
13
14
  it "passes" do
14
15
  expect do
15
- response.should redirect_to("destination")
16
+ expect(response).to redirect_to("destination")
16
17
  end.to_not raise_exception
17
18
  end
18
19
  end
@@ -24,7 +25,7 @@ describe "redirect_to" do
24
25
 
25
26
  it "uses failure message from assert_redirected_to" do
26
27
  expect do
27
- response.should redirect_to("destination")
28
+ expect(response).to redirect_to("destination")
28
29
  end.to raise_exception("this message")
29
30
  end
30
31
  end
@@ -36,7 +37,7 @@ describe "redirect_to" do
36
37
 
37
38
  it "raises that exception" do
38
39
  expect do
39
- response.should redirect_to("destination")
40
+ expect(response).to redirect_to("destination")
40
41
  end.to raise_exception("oops")
41
42
  end
42
43
  end
@@ -50,7 +51,7 @@ describe "redirect_to" do
50
51
 
51
52
  it "passes" do
52
53
  expect do
53
- response.should_not redirect_to("destination")
54
+ expect(response).not_to redirect_to("destination")
54
55
  end.to_not raise_exception
55
56
  end
56
57
  end
@@ -60,7 +61,7 @@ describe "redirect_to" do
60
61
 
61
62
  it "fails with custom failure message" do
62
63
  expect do
63
- response.should_not redirect_to("destination")
64
+ expect(response).not_to redirect_to("destination")
64
65
  end.to raise_exception(/expected not to redirect to \"destination\", but did/)
65
66
  end
66
67
  end
@@ -72,7 +73,7 @@ describe "redirect_to" do
72
73
 
73
74
  it "raises that exception" do
74
75
  expect do
75
- response.should_not redirect_to("destination")
76
+ expect(response).not_to redirect_to("destination")
76
77
  end.to raise_exception("oops")
77
78
  end
78
79
  end
@@ -1,31 +1,31 @@
1
1
  require "spec_helper"
2
2
 
3
- describe "ActiveSupport::Relation =~ matcher" do
3
+ describe "ActiveSupport::Relation match_array matcher" do
4
4
  before { MockableModel.delete_all }
5
5
 
6
6
  let!(:models) { Array.new(3) { MockableModel.create } }
7
7
 
8
8
  if ::Rails::VERSION::STRING >= '4'
9
9
  it "verifies that the scope returns the records on the right hand side, regardless of order" do
10
- MockableModel.all.should =~ models.reverse
10
+ expect(MockableModel.all).to match_array(models.reverse)
11
11
  end
12
12
 
13
13
  it "fails if the scope encompasses more records than on the right hand side" do
14
14
  MockableModel.create
15
- MockableModel.all.should_not =~ models.reverse
15
+ expect(MockableModel.all).not_to match_array(models.reverse)
16
16
  end
17
17
  else
18
18
  it "verifies that the scope returns the records on the right hand side, regardless of order" do
19
- MockableModel.scoped.should =~ models.reverse
19
+ expect(MockableModel.scoped).to match_array(models.reverse)
20
20
  end
21
21
 
22
22
  it "fails if the scope encompasses more records than on the right hand side" do
23
23
  MockableModel.create
24
- MockableModel.scoped.should_not =~ models.reverse
24
+ expect(MockableModel.scoped).not_to match_array(models.reverse)
25
25
  end
26
26
  end
27
27
 
28
28
  it "fails if the scope encompasses fewer records than on the right hand side" do
29
- MockableModel.limit(models.length - 1).should_not =~ models.reverse
29
+ expect(MockableModel.limit(models.length - 1)).not_to match_array(models.reverse)
30
30
  end
31
31
  end
@@ -11,45 +11,45 @@ describe "route_to" do
11
11
  it "provides a description" do
12
12
  matcher = route_to("these" => "options")
13
13
  matcher.matches?(:get => "path")
14
- matcher.description.should == "route {:get=>\"path\"} to {\"these\"=>\"options\"}"
14
+ expect(matcher.description).to eq("route {:get=>\"path\"} to {\"these\"=>\"options\"}")
15
15
  end
16
16
 
17
17
  it "delegates to assert_recognizes" do
18
- self.should_receive(:assert_recognizes).with({ "these" => "options" }, { :method=> :get, :path=>"path" }, {})
19
- {:get => "path"}.should route_to("these" => "options")
18
+ expect(self).to receive(:assert_recognizes).with({ "these" => "options" }, { :method=> :get, :path=>"path" }, {})
19
+ expect({:get => "path"}).to route_to("these" => "options")
20
20
  end
21
21
 
22
22
  context "with shortcut syntax" do
23
23
  it "routes with extra options" do
24
- self.should_receive(:assert_recognizes).with({ :controller => "controller", :action => "action", :extra => "options"}, { :method=> :get, :path=>"path" }, {})
25
- get("path").should route_to("controller#action", :extra => "options")
24
+ expect(self).to receive(:assert_recognizes).with({ :controller => "controller", :action => "action", :extra => "options"}, { :method=> :get, :path=>"path" }, {})
25
+ expect(get("path")).to route_to("controller#action", :extra => "options")
26
26
  end
27
27
 
28
28
  it "routes without extra options" do
29
- self.should_receive(:assert_recognizes).with(
29
+ expect(self).to receive(:assert_recognizes).with(
30
30
  {:controller => "controller", :action => "action"},
31
31
  {:method=> :get, :path=>"path" },
32
32
  {}
33
33
  )
34
- get("path").should route_to("controller#action")
34
+ expect(get("path")).to route_to("controller#action")
35
35
  end
36
36
 
37
37
  it "routes with one query parameter" do
38
- self.should_receive(:assert_recognizes).with(
38
+ expect(self).to receive(:assert_recognizes).with(
39
39
  {:controller => "controller", :action => "action", :queryitem => "queryvalue"},
40
40
  {:method=> :get, :path=>"path" },
41
41
  {'queryitem' => 'queryvalue' }
42
42
  )
43
- get("path?queryitem=queryvalue").should route_to("controller#action", :queryitem => 'queryvalue')
43
+ expect(get("path?queryitem=queryvalue")).to route_to("controller#action", :queryitem => 'queryvalue')
44
44
  end
45
45
 
46
46
  it "routes with multiple query parameters" do
47
- self.should_receive(:assert_recognizes).with(
47
+ expect(self).to receive(:assert_recognizes).with(
48
48
  {:controller => "controller", :action => "action", :queryitem => "queryvalue", :qi2 => 'qv2'},
49
49
  {:method=> :get, :path=>"path"},
50
50
  {'queryitem' => 'queryvalue', 'qi2' => 'qv2'}
51
51
  )
52
- get("path?queryitem=queryvalue&qi2=qv2").should route_to("controller#action", :queryitem => 'queryvalue', :qi2 => 'qv2')
52
+ expect(get("path?queryitem=queryvalue&qi2=qv2")).to route_to("controller#action", :queryitem => 'queryvalue', :qi2 => 'qv2')
53
53
  end
54
54
 
55
55
  end
@@ -58,7 +58,7 @@ describe "route_to" do
58
58
  context "when assert_recognizes passes" do
59
59
  it "passes" do
60
60
  expect do
61
- {:get => "path"}.should route_to("these" => "options")
61
+ expect({:get => "path"}).to route_to("these" => "options")
62
62
  end.to_not raise_exception
63
63
  end
64
64
  end
@@ -69,7 +69,7 @@ describe "route_to" do
69
69
  raise ActiveSupport::TestCase::Assertion.new("this message")
70
70
  end
71
71
  expect do
72
- {:get => "path"}.should route_to("these" => "options")
72
+ expect({:get => "path"}).to route_to("these" => "options")
73
73
  end.to raise_error(RSpec::Expectations::ExpectationNotMetError, "this message")
74
74
  end
75
75
  end
@@ -80,7 +80,7 @@ describe "route_to" do
80
80
  raise ActionController::RoutingError.new("this message")
81
81
  end
82
82
  expect do
83
- {:get => "path"}.should route_to("these" => "options")
83
+ expect({:get => "path"}).to route_to("these" => "options")
84
84
  end.to raise_error(RSpec::Expectations::ExpectationNotMetError, "this message")
85
85
  end
86
86
  end
@@ -91,7 +91,7 @@ describe "route_to" do
91
91
  raise "oops"
92
92
  end
93
93
  expect do
94
- {:get => "path"}.should route_to("these" => "options")
94
+ expect({:get => "path"}).to route_to("these" => "options")
95
95
  end.to raise_exception("oops")
96
96
  end
97
97
  end
@@ -101,8 +101,8 @@ describe "route_to" do
101
101
  context "when assert_recognizes passes" do
102
102
  it "fails with custom message" do
103
103
  expect do
104
- {:get => "path"}.should_not route_to("these" => "options")
105
- end.to raise_error(/expected .* not to route to .*/)
104
+ expect({:get => "path"}).not_to route_to("these" => "options")
105
+ end.to raise_error(/expected {:get=>"path"} not to route to {"these"=>"options"}/)
106
106
  end
107
107
  end
108
108
 
@@ -112,7 +112,7 @@ describe "route_to" do
112
112
  raise ActiveSupport::TestCase::Assertion.new("this message")
113
113
  end
114
114
  expect do
115
- {:get => "path"}.should_not route_to("these" => "options")
115
+ expect({:get => "path"}).not_to route_to("these" => "options")
116
116
  end.to_not raise_error
117
117
  end
118
118
  end
@@ -123,7 +123,7 @@ describe "route_to" do
123
123
  raise ActionController::RoutingError.new("this message")
124
124
  end
125
125
  expect do
126
- {:get => "path"}.should_not route_to("these" => "options")
126
+ expect({:get => "path"}).not_to route_to("these" => "options")
127
127
  end.to_not raise_error
128
128
  end
129
129
  end
@@ -134,7 +134,7 @@ describe "route_to" do
134
134
  raise "oops"
135
135
  end
136
136
  expect do
137
- {:get => "path"}.should_not route_to("these" => "options")
137
+ expect({:get => "path"}).not_to route_to("these" => "options")
138
138
  end.to raise_exception("oops")
139
139
  end
140
140
  end
@@ -145,7 +145,7 @@ describe "route_to" do
145
145
  raise ActiveSupport::TestCase::Assertion, "this message"
146
146
  end
147
147
  expect do
148
- {"this" => "path"}.should route_to("these" => "options")
148
+ expect({"this" => "path"}).to route_to("these" => "options")
149
149
  end.to raise_error("this message")
150
150
  end
151
151
  end
@@ -19,4 +19,13 @@ describe RSpec::Rails::MinitestLifecycleAdapter do
19
19
  :before_setup, :after_setup, :example, :before_teardown, :after_teardown
20
20
  ])
21
21
  end
22
+
23
+ it "allows let variables named 'send'" do
24
+ run_result = ::RSpec::Core::ExampleGroup.describe do
25
+ let(:send) { "WHAT" }
26
+ specify { expect(send).to eq "WHAT" }
27
+ end.run NullObject.new
28
+
29
+ expect(run_result).to be true
30
+ end
22
31
  end
@@ -1,12 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "mock_model(RealModel)" do
4
-
5
4
  context "given a String" do
6
5
  context "that does not represent an existing constant" do
7
6
  it "class says it's name" do
8
7
  model = mock_model("Foo")
9
- model.class.name.should eq("Foo")
8
+ expect(model.class.name).to eq("Foo")
10
9
  end
11
10
  end
12
11
 
@@ -14,7 +13,7 @@ describe "mock_model(RealModel)" do
14
13
  context "that extends ActiveModel::Naming" do
15
14
  it "treats the constant as the class" do
16
15
  model = mock_model("MockableModel")
17
- model.class.name.should eq("MockableModel")
16
+ expect(model.class.name).to eq("MockableModel")
18
17
  end
19
18
  end
20
19
 
@@ -42,7 +41,7 @@ describe "mock_model(RealModel)" do
42
41
  end
43
42
 
44
43
  it "is named using the stubbed id value" do
45
- @model.instance_variable_get(:@name).should == "MockableModel_1"
44
+ expect(@model.instance_variable_get(:@name)).to eq("MockableModel_1")
46
45
  end
47
46
  end
48
47
 
@@ -50,7 +49,30 @@ describe "mock_model(RealModel)" do
50
49
  it "sets persisted to false" do
51
50
  model = mock_model(MockableModel)
52
51
  model.destroy
53
- model.should_not be_persisted
52
+ expect(model).not_to be_persisted
53
+ end
54
+ end
55
+
56
+ describe "association" do
57
+ it "constructs a mock association object" do
58
+ model = mock_model(MockableModel)
59
+ expect(model.association(:association_name)).to be
60
+ end
61
+
62
+ it "returns a different association object for each association name" do
63
+ model = mock_model(MockableModel)
64
+ posts = model.association(:posts)
65
+ authors = model.association(:authors)
66
+
67
+ expect(posts).not_to equal(authors)
68
+ end
69
+
70
+ it "returns the same association model each time for the same association name" do
71
+ model = mock_model(MockableModel)
72
+ posts1 = model.association(:posts)
73
+ posts2 = model.association(:posts)
74
+
75
+ expect(posts1).to equal(posts2)
54
76
  end
55
77
  end
56
78
 
@@ -58,21 +80,21 @@ describe "mock_model(RealModel)" do
58
80
  context "default" do
59
81
  it "is empty" do
60
82
  model = mock_model(MockableModel)
61
- model.errors.should be_empty
83
+ expect(model.errors).to be_empty
62
84
  end
63
85
  end
64
86
 
65
87
  context "with :save => false" do
66
88
  it "is not empty" do
67
89
  model = mock_model(MockableModel, :save => false)
68
- model.errors.should_not be_empty
90
+ expect(model.errors).not_to be_empty
69
91
  end
70
92
  end
71
93
 
72
94
  context "with :update_attributes => false" do
73
95
  it "is not empty" do
74
96
  model = mock_model(MockableModel, :save => false)
75
- model.errors.should_not be_empty
97
+ expect(model.errors).not_to be_empty
76
98
  end
77
99
  end
78
100
  end
@@ -81,7 +103,7 @@ describe "mock_model(RealModel)" do
81
103
  it "does not mutate its parameters" do
82
104
  params = {:a => 'b'}
83
105
  mock_model(MockableModel, params)
84
- params.should == {:a => 'b'}
106
+ expect(params).to eq({:a => 'b'})
85
107
  end
86
108
  end
87
109
 
@@ -93,11 +115,11 @@ describe "mock_model(RealModel)" do
93
115
  end
94
116
 
95
117
  it "passes: associated_model == mock" do
96
- @mock_model.should == @real.mockable_model
118
+ expect(@mock_model).to eq(@real.mockable_model)
97
119
  end
98
120
 
99
121
  it "passes: mock == associated_model" do
100
- @real.mockable_model.should == @mock_model
122
+ expect(@real.mockable_model).to eq(@mock_model)
101
123
  end
102
124
  end
103
125
 
@@ -109,11 +131,11 @@ describe "mock_model(RealModel)" do
109
131
  end
110
132
 
111
133
  it "passes: associated_model == mock" do
112
- @mock_model.should == @real.nonexistent_model
134
+ expect(@mock_model).to eq(@real.nonexistent_model)
113
135
  end
114
136
 
115
137
  it "passes: mock == associated_model" do
116
- @real.nonexistent_model.should == @mock_model
138
+ expect(@real.nonexistent_model).to eq(@mock_model)
117
139
  end
118
140
  end
119
141
 
@@ -121,17 +143,17 @@ describe "mock_model(RealModel)" do
121
143
  before(:each) do
122
144
  @model = mock_model(SubMockableModel)
123
145
  end
124
-
146
+
125
147
  it "says it is_a?(RealModel)" do
126
- @model.is_a?(SubMockableModel).should be(true)
148
+ expect(@model.is_a?(SubMockableModel)).to be(true)
127
149
  end
128
-
150
+
129
151
  it "says it is_a?(OtherModel) if RealModel is an ancestors" do
130
- @model.is_a?(MockableModel).should be(true)
152
+ expect(@model.is_a?(MockableModel)).to be(true)
131
153
  end
132
-
154
+
133
155
  it "can be stubbed" do
134
- mock_model(MockableModel, :is_a? => true).is_a?(:Foo).should be_truthy
156
+ expect(mock_model(MockableModel, :is_a? => true).is_a?(:Foo)).to be_truthy
135
157
  end
136
158
  end
137
159
 
@@ -139,17 +161,17 @@ describe "mock_model(RealModel)" do
139
161
  before(:each) do
140
162
  @model = mock_model(SubMockableModel)
141
163
  end
142
-
164
+
143
165
  it "says it is kind_of? if RealModel is" do
144
- @model.kind_of?(SubMockableModel).should be(true)
166
+ expect(@model.kind_of?(SubMockableModel)).to be(true)
145
167
  end
146
-
168
+
147
169
  it "says it is kind_of? if RealModel's ancestor is" do
148
- @model.kind_of?(MockableModel).should be(true)
170
+ expect(@model.kind_of?(MockableModel)).to be(true)
149
171
  end
150
-
172
+
151
173
  it "can be stubbed" do
152
- mock_model(MockableModel, :kind_of? => true).kind_of?(:Foo).should be_truthy
174
+ expect(mock_model(MockableModel, :kind_of? => true).kind_of?(:Foo)).to be_truthy
153
175
  end
154
176
  end
155
177
 
@@ -157,24 +179,24 @@ describe "mock_model(RealModel)" do
157
179
  before(:each) do
158
180
  @model = mock_model(SubMockableModel)
159
181
  end
160
-
182
+
161
183
  it "says it is instance_of? if RealModel is" do
162
- @model.instance_of?(SubMockableModel).should be(true)
184
+ expect(@model.instance_of?(SubMockableModel)).to be(true)
163
185
  end
164
-
186
+
165
187
  it "does not say it instance_of? if RealModel isn't, even if it's ancestor is" do
166
- @model.instance_of?(MockableModel).should be(false)
188
+ expect(@model.instance_of?(MockableModel)).to be(false)
167
189
  end
168
-
190
+
169
191
  it "can be stubbed" do
170
- mock_model(MockableModel, :instance_of? => true).instance_of?(:Foo).should be_truthy
192
+ expect(mock_model(MockableModel, :instance_of? => true).instance_of?(:Foo)).to be_truthy
171
193
  end
172
194
  end
173
195
 
174
196
  describe "#respond_to?" do
175
197
  context "with an ActiveRecord model" do
176
198
  before(:each) do
177
- MockableModel.stub(:column_names).and_return(["column_a", "column_b"])
199
+ allow(MockableModel).to receive(:column_names).and_return(["column_a", "column_b"])
178
200
  @model = mock_model(MockableModel)
179
201
  end
180
202
 
@@ -186,57 +208,57 @@ describe "mock_model(RealModel)" do
186
208
 
187
209
  context "without as_null_object" do
188
210
  it "says it will respond_to?(key) if RealModel has the attribute 'key'" do
189
- @model.respond_to?("column_a").should be(true)
211
+ expect(@model.respond_to?("column_a")).to be(true)
190
212
  end
191
213
  it "stubs column accessor (with string)" do
192
214
  @model.respond_to?("column_a")
193
- @model.column_a.should be_nil
215
+ expect(@model.column_a).to be_nil
194
216
  end
195
217
  it "stubs column accessor (with symbol)" do
196
218
  @model.respond_to?(:column_a)
197
- @model.column_a.should be_nil
219
+ expect(@model.column_a).to be_nil
198
220
  end
199
221
  it "does not stub column accessor if already stubbed in declaration (with string)" do
200
222
  model = mock_model(MockableModel, "column_a" => "a")
201
223
  model.respond_to?("column_a")
202
- model.column_a.should eq("a")
224
+ expect(model.column_a).to eq("a")
203
225
  end
204
226
  it "does not stub column accessor if already stubbed in declaration (with symbol)" do
205
227
  model = mock_model(MockableModel, :column_a => "a")
206
228
  model.respond_to?("column_a")
207
- model.column_a.should eq("a")
229
+ expect(model.column_a).to eq("a")
208
230
  end
209
231
  it "does not stub column accessor if already stubbed after declaration (with string)" do
210
- @model.stub("column_a" => "a")
232
+ allow(@model).to receive_messages("column_a" => "a")
211
233
  @model.respond_to?("column_a")
212
- @model.column_a.should eq("a")
234
+ expect(@model.column_a).to eq("a")
213
235
  end
214
236
  it "does not stub column accessor if already stubbed after declaration (with symbol)" do
215
- @model.stub(:column_a => "a")
237
+ allow(@model).to receive_messages(:column_a => "a")
216
238
  @model.respond_to?("column_a")
217
- @model.column_a.should eq("a")
239
+ expect(@model.column_a).to eq("a")
218
240
  end
219
241
  it "says it will not respond_to?(key) if RealModel does not have the attribute 'key'" do
220
- @model.respond_to?("column_c").should be(false)
242
+ expect(@model.respond_to?("column_c")).to be(false)
221
243
  end
222
244
  it "says it will not respond_to?(xxx_before_type_cast)" do
223
- @model.respond_to?("title_before_type_cast").should be(false)
245
+ expect(@model.respond_to?("title_before_type_cast")).to be(false)
224
246
  end
225
247
  end
226
-
248
+
227
249
  context "with as_null_object" do
228
250
  it "says it will respond_to?(key) if RealModel has the attribute 'key'" do
229
- @model.as_null_object.respond_to?("column_a").should be(true)
251
+ expect(@model.as_null_object.respond_to?("column_a")).to be(true)
230
252
  end
231
253
  it "says it will respond_to?(key) even if RealModel does not have the attribute 'key'" do
232
- @model.as_null_object.respond_to?("column_c").should be(true)
254
+ expect(@model.as_null_object.respond_to?("column_c")).to be(true)
233
255
  end
234
256
  it "says it will not respond_to?(xxx_before_type_cast)" do
235
- @model.as_null_object.respond_to?("title_before_type_cast").should be(false)
257
+ expect(@model.as_null_object.respond_to?("title_before_type_cast")).to be(false)
236
258
  end
237
259
  it "returns self for any unprepared message" do
238
260
  @model.as_null_object.tap do |x|
239
- x.non_existant_message.should be(@model)
261
+ expect(x.non_existant_message).to be(@model)
240
262
  end
241
263
  end
242
264
  end
@@ -245,39 +267,39 @@ describe "mock_model(RealModel)" do
245
267
  context "with a non-ActiveRecord model" do
246
268
  it "responds as normal" do
247
269
  model = NonActiveRecordModel.new
248
- model.should respond_to(:to_param)
270
+ expect(model).to respond_to(:to_param)
249
271
  end
250
-
272
+
251
273
  context "with as_null_object" do
252
274
  it "says it will not respond_to?(xxx_before_type_cast)" do
253
275
  model = NonActiveRecordModel.new.as_null_object
254
- model.respond_to?("title_before_type_cast").should be(false)
276
+ expect(model.respond_to?("title_before_type_cast")).to be(false)
255
277
  end
256
278
  end
257
279
  end
258
-
280
+
259
281
  it "can be stubbed" do
260
- mock_model(MockableModel, :respond_to? => true).respond_to?(:foo).should be_truthy
282
+ expect(mock_model(MockableModel, :respond_to? => true).respond_to?(:foo)).to be_truthy
261
283
  end
262
284
  end
263
-
285
+
264
286
  describe "#class" do
265
287
  it "returns the mocked model" do
266
- mock_model(MockableModel).class.should eq(MockableModel)
288
+ expect(mock_model(MockableModel).class).to eq(MockableModel)
267
289
  end
268
-
290
+
269
291
  it "can be stubbed" do
270
- mock_model(MockableModel, :class => String).class.should be(String)
292
+ expect(mock_model(MockableModel, :class => String).class).to be(String)
271
293
  end
272
294
  end
273
295
 
274
296
  describe "#to_s" do
275
297
  it "returns (model.name)_(model#to_param)" do
276
- mock_model(MockableModel).to_s.should == "MockableModel_#{to_param}"
298
+ expect(mock_model(MockableModel).to_s).to eq("MockableModel_#{to_param}")
277
299
  end
278
-
300
+
279
301
  it "can be stubbed" do
280
- mock_model(MockableModel, :to_s => "this string").to_s.should == "this string"
302
+ expect(mock_model(MockableModel, :to_s => "this string").to_s).to eq("this string")
281
303
  end
282
304
  end
283
305
 
@@ -285,7 +307,7 @@ describe "mock_model(RealModel)" do
285
307
  context "default" do
286
308
  it "returns false" do
287
309
  @model = mock_model(SubMockableModel)
288
- @model.destroyed?.should be(false)
310
+ expect(@model.destroyed?).to be(false)
289
311
  end
290
312
  end
291
313
  end
@@ -294,7 +316,7 @@ describe "mock_model(RealModel)" do
294
316
  context "default" do
295
317
  it "returns false" do
296
318
  @model = mock_model(SubMockableModel)
297
- @model.marked_for_destruction?.should be(false)
319
+ expect(@model.marked_for_destruction?).to be(false)
298
320
  end
299
321
  end
300
322
  end
@@ -302,19 +324,19 @@ describe "mock_model(RealModel)" do
302
324
  describe "#persisted?" do
303
325
  context "with default identifier" do
304
326
  it "returns true" do
305
- mock_model(MockableModel).should be_persisted
327
+ expect(mock_model(MockableModel)).to be_persisted
306
328
  end
307
329
  end
308
330
 
309
331
  context "with explicit identifier via :id" do
310
332
  it "returns true" do
311
- mock_model(MockableModel, :id => 37).should be_persisted
333
+ expect(mock_model(MockableModel, :id => 37)).to be_persisted
312
334
  end
313
335
  end
314
336
 
315
337
  context "with id => nil" do
316
338
  it "returns false" do
317
- mock_model(MockableModel, :id => nil).should_not be_persisted
339
+ expect(mock_model(MockableModel, :id => nil)).not_to be_persisted
318
340
  end
319
341
  end
320
342
  end
@@ -322,13 +344,13 @@ describe "mock_model(RealModel)" do
322
344
  describe "#valid?" do
323
345
  context "default" do
324
346
  it "returns true" do
325
- mock_model(MockableModel).should be_valid
347
+ expect(mock_model(MockableModel)).to be_valid
326
348
  end
327
349
  end
328
-
350
+
329
351
  context "stubbed with false" do
330
352
  it "returns false" do
331
- mock_model(MockableModel, :valid? => false).should_not be_valid
353
+ expect(mock_model(MockableModel, :valid? => false)).not_to be_valid
332
354
  end
333
355
  end
334
356
  end
@@ -336,26 +358,26 @@ describe "mock_model(RealModel)" do
336
358
  describe "#as_new_record" do
337
359
  it "says it is a new record" do
338
360
  m = mock_model(MockableModel)
339
- m.as_new_record.should be_new_record
361
+ expect(m.as_new_record).to be_new_record
340
362
  end
341
363
 
342
364
  it "says it is not persisted" do
343
365
  m = mock_model(MockableModel)
344
- m.as_new_record.should_not be_persisted
366
+ expect(m.as_new_record).not_to be_persisted
345
367
  end
346
368
 
347
369
  it "has a nil id" do
348
- mock_model(MockableModel).as_new_record.id.should be(nil)
370
+ expect(mock_model(MockableModel).as_new_record.id).to be(nil)
349
371
  end
350
372
 
351
373
  it "returns nil for #to_param" do
352
- mock_model(MockableModel).as_new_record.to_param.should be(nil)
374
+ expect(mock_model(MockableModel).as_new_record.to_param).to be(nil)
353
375
  end
354
376
  end
355
377
 
356
378
  describe "#blank?" do
357
379
  it "is false" do
358
- mock_model(MockableModel).should_not be_blank
380
+ expect(mock_model(MockableModel)).not_to be_blank
359
381
  end
360
382
  end
361
383