Skip to content

Commit 652a77d

Browse files
committed
Generators use newer expect syntax
Closes #839
1 parent e207d0a commit 652a77d

File tree

8 files changed

+29
-29
lines changed

8 files changed

+29
-29
lines changed

lib/generators/rspec/controller/templates/controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
describe "GET '<%= action %>'" do
88
it "returns http success" do
99
get '<%= action %>'
10-
response.should be_success
10+
expect(response).to be_success
1111
end
1212
end
1313

lib/generators/rspec/integration/templates/request_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
1010
get <%= index_helper %>_path
1111
<% end -%>
12-
response.status.should be(200)
12+
expect(response.status).to be(200)
1313
end
1414
end
1515
end

lib/generators/rspec/mailer/templates/mailer_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
let(:mail) { <%= class_name %>.<%= action %> }
88
99
it "renders the headers" do
10-
mail.subject.should eq(<%= action.to_s.humanize.inspect %>)
11-
mail.to.should eq(["[email protected]"])
12-
mail.from.should eq(["[email protected]"])
10+
expect(mail.subject).to eq(<%= action.to_s.humanize.inspect %>)
11+
expect(mail.to).to eq(["[email protected]"])
12+
expect(mail.from).to eq(["[email protected]"])
1313
end
1414
1515
it "renders the body" do
16-
mail.body.encoded.should match("Hi")
16+
expect(mail.body.encoded).to match("Hi")
1717
end
1818
end
1919

lib/generators/rspec/scaffold/templates/controller_spec.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
3737
<%= file_name %> = <%= class_name %>.create! valid_attributes
3838
get :index, {}, valid_session
39-
assigns(:<%= table_name %>).should eq([<%= file_name %>])
39+
expect(assigns(:<%= table_name %>)).to eq([<%= file_name %>])
4040
end
4141
end
4242
@@ -45,22 +45,22 @@
4545
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
4646
<%= file_name %> = <%= class_name %>.create! valid_attributes
4747
get :show, {:id => <%= file_name %>.to_param}, valid_session
48-
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
48+
expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
4949
end
5050
end
5151
5252
describe "GET new" do
5353
it "assigns a new <%= ns_file_name %> as @<%= ns_file_name %>" do
5454
get :new, {}, valid_session
55-
assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
55+
expect(assigns(:<%= ns_file_name %>)).to be_a_new(<%= class_name %>)
5656
end
5757
end
5858
5959
describe "GET edit" do
6060
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
6161
<%= file_name %> = <%= class_name %>.create! valid_attributes
6262
get :edit, {:id => <%= file_name %>.to_param}, valid_session
63-
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
63+
expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
6464
end
6565
end
6666
@@ -74,13 +74,13 @@
7474
7575
it "assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %>" do
7676
post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
77-
assigns(:<%= ns_file_name %>).should be_a(<%= class_name %>)
78-
assigns(:<%= ns_file_name %>).should be_persisted
77+
expect(assigns(:<%= ns_file_name %>)).to be_a(<%= class_name %>)
78+
expect(assigns(:<%= ns_file_name %>)).to be_persisted
7979
end
8080
8181
it "redirects to the created <%= ns_file_name %>" do
8282
post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
83-
response.should redirect_to(<%= class_name %>.last)
83+
expect(response).to redirect_to(<%= class_name %>.last)
8484
end
8585
end
8686
@@ -89,14 +89,14 @@
8989
# Trigger the behavior that occurs when invalid params are submitted
9090
<%= class_name %>.any_instance.stub(:save).and_return(false)
9191
post :create, {:<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
92-
assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
92+
expect(assigns(:<%= ns_file_name %>)).to be_a_new(<%= class_name %>)
9393
end
9494
9595
it "re-renders the 'new' template" do
9696
# Trigger the behavior that occurs when invalid params are submitted
9797
<%= class_name %>.any_instance.stub(:save).and_return(false)
9898
post :create, {:<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
99-
response.should render_template("new")
99+
expect(response).to render_template("new")
100100
end
101101
end
102102
end
@@ -110,23 +110,23 @@
110110
# receives the :update_attributes message with whatever params are
111111
# submitted in the request.
112112
<%- if ::Rails::VERSION::STRING >= '4' -%>
113-
<%= class_name %>.any_instance.should_receive(:update).with(<%= formatted_hash(example_params_for_update) %>)
113+
expect_any_instance_of(<%= class_name %>).to receive(:update).with(<%= formatted_hash(example_params_for_update) %>)
114114
<%- else -%>
115-
<%= class_name %>.any_instance.should_receive(:update_attributes).with(<%= formatted_hash(example_params_for_update) %>)
115+
expect_any_instance_of(<%= class_name %>).to receive(:update_attributes).with(<%= formatted_hash(example_params_for_update) %>)
116116
<%- end -%>
117117
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= formatted_hash(example_params_for_update) %>}, valid_session
118118
end
119119
120120
it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
121121
<%= file_name %> = <%= class_name %>.create! valid_attributes
122122
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
123-
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
123+
expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
124124
end
125125
126126
it "redirects to the <%= ns_file_name %>" do
127127
<%= file_name %> = <%= class_name %>.create! valid_attributes
128128
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
129-
response.should redirect_to(<%= file_name %>)
129+
expect(response).to redirect_to(<%= file_name %>)
130130
end
131131
end
132132
@@ -136,15 +136,15 @@
136136
# Trigger the behavior that occurs when invalid params are submitted
137137
<%= class_name %>.any_instance.stub(:save).and_return(false)
138138
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
139-
assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
139+
expect(assigns(:<%= ns_file_name %>)).to eq(<%= file_name %>)
140140
end
141141
142142
it "re-renders the 'edit' template" do
143143
<%= file_name %> = <%= class_name %>.create! valid_attributes
144144
# Trigger the behavior that occurs when invalid params are submitted
145145
<%= class_name %>.any_instance.stub(:save).and_return(false)
146146
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= formatted_hash(example_invalid_attributes) %>}, valid_session
147-
response.should render_template("edit")
147+
expect(response).to render_template("edit")
148148
end
149149
end
150150
end
@@ -160,7 +160,7 @@
160160
it "redirects to the <%= table_name %> list" do
161161
<%= file_name %> = <%= class_name %>.create! valid_attributes
162162
delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
163-
response.should redirect_to(<%= index_helper %>_url)
163+
expect(response).to redirect_to(<%= index_helper %>_url)
164164
end
165165
end
166166

lib/generators/rspec/scaffold/templates/edit_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
render
1515
1616
<% if webrat? -%>
17-
rendered.should have_selector("form", :action => <%= ns_file_name %>_path(@<%= ns_file_name %>), :method => "post") do |form|
17+
expect(rendered).to have_selector("form", :action => <%= ns_file_name %>_path(@<%= ns_file_name %>), :method => "post") do |form|
1818
<% for attribute in output_attributes -%>
19-
form.should have_selector("<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]")
19+
expect(form).to have_selector("<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]")
2020
<% end -%>
2121
end
2222
<% else -%>

lib/generators/rspec/scaffold/templates/index_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<% end -%>
2424
<% for attribute in output_attributes -%>
2525
<% if webrat? -%>
26-
rendered.should have_selector("tr>td", :content => <%= value_for(attribute) %>.to_s, :count => 2)
26+
expect(rendered).to have_selector("tr>td", :content => <%= value_for(attribute) %>.to_s, :count => 2)
2727
<% else -%>
2828
assert_select "tr>td", :text => <%= value_for(attribute) %>.to_s, :count => 2
2929
<% end -%>

lib/generators/rspec/scaffold/templates/new_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
render
1414
1515
<% if webrat? -%>
16-
rendered.should have_selector("form", :action => <%= table_name %>_path, :method => "post") do |form|
16+
expect(rendered).to have_selector("form", :action => <%= table_name %>_path, :method => "post") do |form|
1717
<% for attribute in output_attributes -%>
18-
form.should have_selector("<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]")
18+
expect(form).to have_selector("<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]")
1919
<% end -%>
2020
end
2121
<% else -%>

lib/generators/rspec/scaffold/templates/show_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
<% end -%>
2020
<% for attribute in output_attributes -%>
2121
<% if webrat? -%>
22-
rendered.should contain(<%= value_for(attribute) %>.to_s)
22+
expect(rendered).to contain(<%= value_for(attribute) %>.to_s)
2323
<% else -%>
24-
rendered.should match(/<%= eval(value_for(attribute)) %>/)
24+
expect(rendered).to match(/<%= eval(value_for(attribute)) %>/)
2525
<% end -%>
2626
<% end -%>
2727
end

0 commit comments

Comments
 (0)