I'm using Capybara with webkit for my testing, but for some reason when a test fails it shows the error, but not where it actually occurred in the code.
Failures:
1) online shopping - sign up
Failure/Error: page.should have_content 'Payment added successfully'
expected there to be content "Payment added successfully" in "Internal Server Error undefined method `client_id' for #<InvoicePayment:0x007fbd5b834008> WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20) at 127.0.0.1:60324"
# ./spec/requests/online_shopping_spec.rb:140:in `block (2 levels) in <top (required)>'
and when using save_and_open_page it'll just show the error, with no information on where it occured:
Internal Server Error
undefined method `client_id' for #
WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20) at 127.0.0.1:60324
What I'm expecting to see is the line number and function where the error occured:
app/controllers/invoices_controller.rb:30:in `show'
I can't seem to find anything related to this on Google. I'm probably using incorrect nomenclature. Anybody know how to fix this?
Basically capybara does not have a knowledge about the app, since it's running in the different process. You could workaround this problem using this a trick described here https://gist.github.com/1443408
The problem is that the actual page is not rendering because of an error, and instead you are getting an internal server error. So Internal Server Error undefined method... is the content of the page you are testing. RSpec/Capybara can't tell you where it occurred because the test framework only tests what you actually see on the page, and that is exactly what you see (as you confirmed when you ran save_and_open_page).
To track down the error you should look at your rails error log, or the console/terminal where you are running it from. Without more information I can't help you track down the error.
Hope that helps.
Related
So I recently pulled in the Rails best practices gem and it said I should use the current_user.find instead of doing it a different way. The issue is, this of course throws ActiveRecord::RecordNotFound when the current_user doesn't have the record. Now in my integration tests, I explicitly test that a user cannot access another users records. This causes the error to be thrown. The issue is, I want to handle this error since I expect it to be thrown. It's currently making my tests red. How can I get my tests to go green, while still testing that the error is thrown? Any help is clarification on best practices would be greatly appreciated! Thank you!
sidenote
As you can see, I'm attempting to use assert_raise. Which isn't catching the error of course... And assert_field_no_difference is just one of my helper methods..
Also, I've been searching for answers for a while now. Most people address how to handle it within the controller, in respect to render a page, or redirecting, but I haven't found anyone addressing how to handle it as expected behavior within a test.
my integration test
test "tries to edit resource not associated with user" do
login(#user)
assert_field_no_difference #resource, 'url' do
assert_raise ActiveRecord::RecordNotFound do
put community_resource_path(#resource), params: { community_resource: {
url: 'http://www.example.com'}}
end
end
end
error being thown as expected
Error:
Community::ResourcesFlowsTest#test_tries_to_edit_resource_not_associated_with_user:
ActiveRecord::RecordNotFound: Couldn't find Community::Resource with 'id'=1 [WHERE "community_resources"."user_id" = $1]
app/controllers/community/resources_controller.rb:106:in `set_allowable_access_resource'
test/integration/community/resources_flows_test.rb:110:in `block in <class:ResourcesFlowsTest>'
ENV=development
Im getting a weird error that makes no sense to me
when i run an integration test with Myclass.count I get error
ERROR["test_micropost_interface", MicropostsInterfaceTest, 2016-01-20 23:50:17 +0000]
test_micropost_interface#MicropostsInterfaceTest (1453333817.28s)
ActionView::Template::Error: ActionView::Template::Error: undefined method `count' for nil:NilClass
the code is and was working im sure !
assert_no_difference 'Micropost.count' do
post microposts_path, micropost: { content: "" }
end
I ran a console and Micropost.count returns 32
Is this possibly an issue with the fixtures not propagating ?
im stumped :( take advice on where to look !
I think the error is coming from within one of your views rather than being a problem with the test itself.
It's probably worth removing the silencing on backtraces and seeing if you get a more detailed error which will hopefully point to the error more accurately.
In config/initializers/backtrace_silencers.rb you can uncomment the last line to get rails to show the entirety of an error. I often change this line to:
Rails.backtrace_cleaner.remove_silencers! if Rails.env.test?
to get full backtraces when I'm running tests.
I get this error arbitrarily during certain actions in my application. I feel this error is due to #app.call(env) in one of my middlewares.
NoMethodError (undefined method `action_name' for nil:NilClass):
vendor/cache/ruby/2.1.0/gems/actionpack-3.2.22/lib/action_controller/caching/sweeping.rb:84:in `callback'
vendor/cache/ruby/2.1.0/gems/actionpack-3.2.22/lib/action_controller/caching/sweeping.rb:59:in `before'
vendor/cache/ruby/2.1.0/gems/activesupport-3.2.22/lib/active_support/callbacks.rb:325:in `around'
Here's the full-trace of exception.
Origin of exception according to trace.
Similar exception has been reported on google forum but I am not able to conclude anything out of it.
Why is this error even raised at first place ?
Any solution to avoid it ?
Trying to reproduce in a confined environment. Have anybody faced such issue and successfully reproduced it ? (Please share)
Resque-web is up and running but when trying to view the failed jobs I get the following error:
NoMethodError at /failed
undefined method `to_yaml' for 3:Fixnum
The stack trace points to a 'to_yaml' call as mentioned in the error, it seems like resque-web is missing a requires. Has anyone else had this problem or know how to solve it?
Note: I'm running this locally on a rails 4 app.
You can see the reason here: https://github.com/resque/resque/issues/1143 -- it boils down to a temporary bug that is fixed, but not released yet. I fixed mine by adding
require 'yaml'
at the top of the server.rb file
note that the server.rb file on my machine was located at:
/usr/local/lib/ruby/gems/2.0.0/gems/resque-1.25.1/lib/resque/server.rb
your location may vary
When I run rspec on my rails project I get a very annoying error message, although exact the same code worked before. The only thing I did was adding a new rspec file. Now the new rspec file doesn't contain anything except for "require 'spec_helper'" but I still get this message (and a few others...):
1) Home Page should have 'Lists' and 'Students' links
Failure/Error: visit home_path
NameError:
undefined local variable or method home_path' for > #<RSpec::Core::ExampleGroup::Nested_2:0x00000004c455a0>
# ./spec/requests/homes_spec.rb:5:inblock (2 levels) in '
I have no idea what to do now. Has anyone a clue what's the matter with it?
Thanks
According to your routes proper helper would be home_index_path.
Try to use it.