Ruby on Rails - Rspec 3.8, Rails 5, FacotryBot POST redirect test failure
I am following the Ruby on Rails restaurantly tutorial found here: http://rubyonrailstutor.github.io/. First of all I have had to make some changes, much by trial and error and searching errors online. Much of it is due to the fact that it's an old tutorial on an older version of Ruby and Rails.
I am using rails 5.2.1 and Ruby 2.5.3 as well as the latest version of most of the gems. I have successfully completed the tutorial up to the last rspec
test found here: http://rubyonrailstutor.github.io/new/restaurants-new-create/.
When I run rspec spec/requests/restaurants_spec.rb
I get the following error:
Failures:
1) RestaurantsController POST /restaurants complete params redirects to show
Failure/Error: expect(subject).to redirect_to restaurant_path(id:1)
Expected response to be a redirect to <http://www.example.com/restaurants/1> but was a redirect to <http://www.example.com/restaurants/new>.
Expected "http://www.example.com/restaurants/1" to be === "http://www.example.com/restaurants/new".
# ./spec/requests/restaurant_spec.rb:32:in `block (4 levels) in <top (required)>'
Finished in 0.60375 seconds (files took 1.47 seconds to load)
5 examples, 1 failure
Failed examples:
rspec ./spec/requests/restaurant_spec.rb:31 # RestaurantsController POST /restaurants complete params redirects to show
My controller is the same as what the author of the tutorial is using: https://github.com/rubyonrailstutor/restaurantly/blob/restaurants-new/app/controllers/restaurants_controller.rb.
The part of my spec file which is failing is:
context "POST /restaurants" do
context "complete params" do
subject{ post "/restaurants", params: { name: "mcrails"}}
it "redirects to show" do
expect(subject).to redirect_to restaurant_path(id:1)
end
end
context "incomplete params" do
subject{ post "/restaurants", {}}
it "redirects to new" do
expect(subject).to redirect_to(new_restaurant_path)
end
end
end
My subject is slightly different than how the author uses it and I am wondering of this is what I am getting wrong. I changed it when I was getting a number of arguments error which I believe is due to versioning differences. The original looks like this:
restaurant = {restaurant: {name: "mcrails"}}
subject{ post "/restaurants", restaurant }
Which I have changed to this:
subject{ post "/restaurants", params: { name: "mcrails"}}
The author's spec file on rails 4:
https://github.com/rubyonrailstutor/restaurantly/blob/restaurants-new/spec/requests/restaurant_spec.rb.
When I am running the web server and create a new item it redirects to #show the item properly. However the rspec test fails. So I believe I am not running the test properly. Perhaps due to the version difference and the params I am passing but I can't figure this one out. My Rails experience is very minimal at this point.
ruby-on-rails ruby rspec-rails
add a comment |
I am following the Ruby on Rails restaurantly tutorial found here: http://rubyonrailstutor.github.io/. First of all I have had to make some changes, much by trial and error and searching errors online. Much of it is due to the fact that it's an old tutorial on an older version of Ruby and Rails.
I am using rails 5.2.1 and Ruby 2.5.3 as well as the latest version of most of the gems. I have successfully completed the tutorial up to the last rspec
test found here: http://rubyonrailstutor.github.io/new/restaurants-new-create/.
When I run rspec spec/requests/restaurants_spec.rb
I get the following error:
Failures:
1) RestaurantsController POST /restaurants complete params redirects to show
Failure/Error: expect(subject).to redirect_to restaurant_path(id:1)
Expected response to be a redirect to <http://www.example.com/restaurants/1> but was a redirect to <http://www.example.com/restaurants/new>.
Expected "http://www.example.com/restaurants/1" to be === "http://www.example.com/restaurants/new".
# ./spec/requests/restaurant_spec.rb:32:in `block (4 levels) in <top (required)>'
Finished in 0.60375 seconds (files took 1.47 seconds to load)
5 examples, 1 failure
Failed examples:
rspec ./spec/requests/restaurant_spec.rb:31 # RestaurantsController POST /restaurants complete params redirects to show
My controller is the same as what the author of the tutorial is using: https://github.com/rubyonrailstutor/restaurantly/blob/restaurants-new/app/controllers/restaurants_controller.rb.
The part of my spec file which is failing is:
context "POST /restaurants" do
context "complete params" do
subject{ post "/restaurants", params: { name: "mcrails"}}
it "redirects to show" do
expect(subject).to redirect_to restaurant_path(id:1)
end
end
context "incomplete params" do
subject{ post "/restaurants", {}}
it "redirects to new" do
expect(subject).to redirect_to(new_restaurant_path)
end
end
end
My subject is slightly different than how the author uses it and I am wondering of this is what I am getting wrong. I changed it when I was getting a number of arguments error which I believe is due to versioning differences. The original looks like this:
restaurant = {restaurant: {name: "mcrails"}}
subject{ post "/restaurants", restaurant }
Which I have changed to this:
subject{ post "/restaurants", params: { name: "mcrails"}}
The author's spec file on rails 4:
https://github.com/rubyonrailstutor/restaurantly/blob/restaurants-new/spec/requests/restaurant_spec.rb.
When I am running the web server and create a new item it redirects to #show the item properly. However the rspec test fails. So I believe I am not running the test properly. Perhaps due to the version difference and the params I am passing but I can't figure this one out. My Rails experience is very minimal at this point.
ruby-on-rails ruby rspec-rails
Checkout their documentation. It gives examples for post/pre rails 5.
– Mark Merritt
Nov 23 '18 at 18:19
@MarkMerritt Thanks for the link. I had previously found similar examples on their request-specs documentation page. But failed to figure it out. Using your link I spent more time trying to modify the syntax and it looks like I was finally able to get it to work as expected! Thank you very much.
– TheBrianGuy
Nov 23 '18 at 21:18
add a comment |
I am following the Ruby on Rails restaurantly tutorial found here: http://rubyonrailstutor.github.io/. First of all I have had to make some changes, much by trial and error and searching errors online. Much of it is due to the fact that it's an old tutorial on an older version of Ruby and Rails.
I am using rails 5.2.1 and Ruby 2.5.3 as well as the latest version of most of the gems. I have successfully completed the tutorial up to the last rspec
test found here: http://rubyonrailstutor.github.io/new/restaurants-new-create/.
When I run rspec spec/requests/restaurants_spec.rb
I get the following error:
Failures:
1) RestaurantsController POST /restaurants complete params redirects to show
Failure/Error: expect(subject).to redirect_to restaurant_path(id:1)
Expected response to be a redirect to <http://www.example.com/restaurants/1> but was a redirect to <http://www.example.com/restaurants/new>.
Expected "http://www.example.com/restaurants/1" to be === "http://www.example.com/restaurants/new".
# ./spec/requests/restaurant_spec.rb:32:in `block (4 levels) in <top (required)>'
Finished in 0.60375 seconds (files took 1.47 seconds to load)
5 examples, 1 failure
Failed examples:
rspec ./spec/requests/restaurant_spec.rb:31 # RestaurantsController POST /restaurants complete params redirects to show
My controller is the same as what the author of the tutorial is using: https://github.com/rubyonrailstutor/restaurantly/blob/restaurants-new/app/controllers/restaurants_controller.rb.
The part of my spec file which is failing is:
context "POST /restaurants" do
context "complete params" do
subject{ post "/restaurants", params: { name: "mcrails"}}
it "redirects to show" do
expect(subject).to redirect_to restaurant_path(id:1)
end
end
context "incomplete params" do
subject{ post "/restaurants", {}}
it "redirects to new" do
expect(subject).to redirect_to(new_restaurant_path)
end
end
end
My subject is slightly different than how the author uses it and I am wondering of this is what I am getting wrong. I changed it when I was getting a number of arguments error which I believe is due to versioning differences. The original looks like this:
restaurant = {restaurant: {name: "mcrails"}}
subject{ post "/restaurants", restaurant }
Which I have changed to this:
subject{ post "/restaurants", params: { name: "mcrails"}}
The author's spec file on rails 4:
https://github.com/rubyonrailstutor/restaurantly/blob/restaurants-new/spec/requests/restaurant_spec.rb.
When I am running the web server and create a new item it redirects to #show the item properly. However the rspec test fails. So I believe I am not running the test properly. Perhaps due to the version difference and the params I am passing but I can't figure this one out. My Rails experience is very minimal at this point.
ruby-on-rails ruby rspec-rails
I am following the Ruby on Rails restaurantly tutorial found here: http://rubyonrailstutor.github.io/. First of all I have had to make some changes, much by trial and error and searching errors online. Much of it is due to the fact that it's an old tutorial on an older version of Ruby and Rails.
I am using rails 5.2.1 and Ruby 2.5.3 as well as the latest version of most of the gems. I have successfully completed the tutorial up to the last rspec
test found here: http://rubyonrailstutor.github.io/new/restaurants-new-create/.
When I run rspec spec/requests/restaurants_spec.rb
I get the following error:
Failures:
1) RestaurantsController POST /restaurants complete params redirects to show
Failure/Error: expect(subject).to redirect_to restaurant_path(id:1)
Expected response to be a redirect to <http://www.example.com/restaurants/1> but was a redirect to <http://www.example.com/restaurants/new>.
Expected "http://www.example.com/restaurants/1" to be === "http://www.example.com/restaurants/new".
# ./spec/requests/restaurant_spec.rb:32:in `block (4 levels) in <top (required)>'
Finished in 0.60375 seconds (files took 1.47 seconds to load)
5 examples, 1 failure
Failed examples:
rspec ./spec/requests/restaurant_spec.rb:31 # RestaurantsController POST /restaurants complete params redirects to show
My controller is the same as what the author of the tutorial is using: https://github.com/rubyonrailstutor/restaurantly/blob/restaurants-new/app/controllers/restaurants_controller.rb.
The part of my spec file which is failing is:
context "POST /restaurants" do
context "complete params" do
subject{ post "/restaurants", params: { name: "mcrails"}}
it "redirects to show" do
expect(subject).to redirect_to restaurant_path(id:1)
end
end
context "incomplete params" do
subject{ post "/restaurants", {}}
it "redirects to new" do
expect(subject).to redirect_to(new_restaurant_path)
end
end
end
My subject is slightly different than how the author uses it and I am wondering of this is what I am getting wrong. I changed it when I was getting a number of arguments error which I believe is due to versioning differences. The original looks like this:
restaurant = {restaurant: {name: "mcrails"}}
subject{ post "/restaurants", restaurant }
Which I have changed to this:
subject{ post "/restaurants", params: { name: "mcrails"}}
The author's spec file on rails 4:
https://github.com/rubyonrailstutor/restaurantly/blob/restaurants-new/spec/requests/restaurant_spec.rb.
When I am running the web server and create a new item it redirects to #show the item properly. However the rspec test fails. So I believe I am not running the test properly. Perhaps due to the version difference and the params I am passing but I can't figure this one out. My Rails experience is very minimal at this point.
ruby-on-rails ruby rspec-rails
ruby-on-rails ruby rspec-rails
asked Nov 23 '18 at 18:03
TheBrianGuy
1015
1015
Checkout their documentation. It gives examples for post/pre rails 5.
– Mark Merritt
Nov 23 '18 at 18:19
@MarkMerritt Thanks for the link. I had previously found similar examples on their request-specs documentation page. But failed to figure it out. Using your link I spent more time trying to modify the syntax and it looks like I was finally able to get it to work as expected! Thank you very much.
– TheBrianGuy
Nov 23 '18 at 21:18
add a comment |
Checkout their documentation. It gives examples for post/pre rails 5.
– Mark Merritt
Nov 23 '18 at 18:19
@MarkMerritt Thanks for the link. I had previously found similar examples on their request-specs documentation page. But failed to figure it out. Using your link I spent more time trying to modify the syntax and it looks like I was finally able to get it to work as expected! Thank you very much.
– TheBrianGuy
Nov 23 '18 at 21:18
Checkout their documentation. It gives examples for post/pre rails 5.
– Mark Merritt
Nov 23 '18 at 18:19
Checkout their documentation. It gives examples for post/pre rails 5.
– Mark Merritt
Nov 23 '18 at 18:19
@MarkMerritt Thanks for the link. I had previously found similar examples on their request-specs documentation page. But failed to figure it out. Using your link I spent more time trying to modify the syntax and it looks like I was finally able to get it to work as expected! Thank you very much.
– TheBrianGuy
Nov 23 '18 at 21:18
@MarkMerritt Thanks for the link. I had previously found similar examples on their request-specs documentation page. But failed to figure it out. Using your link I spent more time trying to modify the syntax and it looks like I was finally able to get it to work as expected! Thank you very much.
– TheBrianGuy
Nov 23 '18 at 21:18
add a comment |
1 Answer
1
active
oldest
votes
@MarkMerritt pointed me to documentation that helped me with some trial and error figure out how to make it work.
While I still don't completely understand the differences in syntax between the tutorial and what I was able to get working I will post my final spec file edits in case anyone has any feedback.
context "POST /restaurants" do
context "complete params" do
subject { post "/restaurants", :params => { :restaurant => { :name => "mcrails" } } }
it "redirects to show" do
expect(subject).to redirect_to restaurant_path(:id => assigns(:restaurant).id)
end
end
context "incomplete params" do
subject { post "/restaurants", :params => {} }
it "redirects to new" do
expect(subject).to redirect_to(new_restaurant_path)
end
end
end
The use of explicit subject in that tutorial is pretty questionable.blog.davidchelimsky.net/blog/2012/05/13/…
– max
Nov 23 '18 at 21:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451210%2fruby-on-rails-rspec-3-8-rails-5-facotrybot-post-redirect-test-failure%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
@MarkMerritt pointed me to documentation that helped me with some trial and error figure out how to make it work.
While I still don't completely understand the differences in syntax between the tutorial and what I was able to get working I will post my final spec file edits in case anyone has any feedback.
context "POST /restaurants" do
context "complete params" do
subject { post "/restaurants", :params => { :restaurant => { :name => "mcrails" } } }
it "redirects to show" do
expect(subject).to redirect_to restaurant_path(:id => assigns(:restaurant).id)
end
end
context "incomplete params" do
subject { post "/restaurants", :params => {} }
it "redirects to new" do
expect(subject).to redirect_to(new_restaurant_path)
end
end
end
The use of explicit subject in that tutorial is pretty questionable.blog.davidchelimsky.net/blog/2012/05/13/…
– max
Nov 23 '18 at 21:51
add a comment |
@MarkMerritt pointed me to documentation that helped me with some trial and error figure out how to make it work.
While I still don't completely understand the differences in syntax between the tutorial and what I was able to get working I will post my final spec file edits in case anyone has any feedback.
context "POST /restaurants" do
context "complete params" do
subject { post "/restaurants", :params => { :restaurant => { :name => "mcrails" } } }
it "redirects to show" do
expect(subject).to redirect_to restaurant_path(:id => assigns(:restaurant).id)
end
end
context "incomplete params" do
subject { post "/restaurants", :params => {} }
it "redirects to new" do
expect(subject).to redirect_to(new_restaurant_path)
end
end
end
The use of explicit subject in that tutorial is pretty questionable.blog.davidchelimsky.net/blog/2012/05/13/…
– max
Nov 23 '18 at 21:51
add a comment |
@MarkMerritt pointed me to documentation that helped me with some trial and error figure out how to make it work.
While I still don't completely understand the differences in syntax between the tutorial and what I was able to get working I will post my final spec file edits in case anyone has any feedback.
context "POST /restaurants" do
context "complete params" do
subject { post "/restaurants", :params => { :restaurant => { :name => "mcrails" } } }
it "redirects to show" do
expect(subject).to redirect_to restaurant_path(:id => assigns(:restaurant).id)
end
end
context "incomplete params" do
subject { post "/restaurants", :params => {} }
it "redirects to new" do
expect(subject).to redirect_to(new_restaurant_path)
end
end
end
@MarkMerritt pointed me to documentation that helped me with some trial and error figure out how to make it work.
While I still don't completely understand the differences in syntax between the tutorial and what I was able to get working I will post my final spec file edits in case anyone has any feedback.
context "POST /restaurants" do
context "complete params" do
subject { post "/restaurants", :params => { :restaurant => { :name => "mcrails" } } }
it "redirects to show" do
expect(subject).to redirect_to restaurant_path(:id => assigns(:restaurant).id)
end
end
context "incomplete params" do
subject { post "/restaurants", :params => {} }
it "redirects to new" do
expect(subject).to redirect_to(new_restaurant_path)
end
end
end
answered Nov 23 '18 at 21:29
TheBrianGuy
1015
1015
The use of explicit subject in that tutorial is pretty questionable.blog.davidchelimsky.net/blog/2012/05/13/…
– max
Nov 23 '18 at 21:51
add a comment |
The use of explicit subject in that tutorial is pretty questionable.blog.davidchelimsky.net/blog/2012/05/13/…
– max
Nov 23 '18 at 21:51
The use of explicit subject in that tutorial is pretty questionable.blog.davidchelimsky.net/blog/2012/05/13/…
– max
Nov 23 '18 at 21:51
The use of explicit subject in that tutorial is pretty questionable.blog.davidchelimsky.net/blog/2012/05/13/…
– max
Nov 23 '18 at 21:51
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451210%2fruby-on-rails-rspec-3-8-rails-5-facotrybot-post-redirect-test-failure%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Checkout their documentation. It gives examples for post/pre rails 5.
– Mark Merritt
Nov 23 '18 at 18:19
@MarkMerritt Thanks for the link. I had previously found similar examples on their request-specs documentation page. But failed to figure it out. Using your link I spent more time trying to modify the syntax and it looks like I was finally able to get it to work as expected! Thank you very much.
– TheBrianGuy
Nov 23 '18 at 21:18