Rails Failure ---expected +++ actual ## -1 +1 ## - ruby-on-rails

I am working on the Michael Hartl tutorial. When running my test, I get the following failure:
1) Failure:
SessionsHelperTest#test_current_user_returns_right_user_when_session_is_nil
[/home.../myapplication/test/helpers/sessions_helper_test.rb:11]:
--- expected
+++ actual
## -1 +1 ##
-#<User id:... >
+nil
Could anyone help make sense of this failure especially the following:
--- expected
+++ actual
## -1 +1 ##
Is there any official documentation from rails that gives guidance on those find of failure message? I have not found any. Thanks.

I do not know this tutorial and I don't know almost nothing of test but I think you have a error in your app. You get a nil output +nil and the expected output is a User element -#<User id:... >
Maybe you have wrong User.where clause
If you put more info I can try help more

My problem was that I had def current_user twice in app/helpers/sessions_helper.rb and one of them was outdated.

Related

Not able to execute any test case in rspec

I am really confused about this Psych BadAlias error.
I have tried everything but not able to debug this error.
When i am executing my test case i am getting this error
Failure/Error: #st.fetch(o.anchor) { raise BadAlias, "Unknown alias: #{o.anchor}" }
Psych::BadAlias:
Unknown alias: 2
But before it was working perfectly fine.
This is my fixtures file
workers.yml
Worker_1:
name: Hello
preferred_first_name: First
preferred_last_name: Last
assignment: Assignemnt_1
talent: Ruby_development
Any kind of Help is appreciated!
Thanks
A Psych::BadAlias exception will be raised if the yaml contains aliases but the aliases keyword argument is set to false.
Please check your yaml files. The error got raised from here. For more details please refer here
I solved it, as there was just a syntax error in yaaml file.
we canot use "p-r-a-t-i-k" we have to use "p_r_a_t_i_k"

Rails 5: Error when removed quiet_assets_path from development.rb

I have been trying to upgrade my app from Rails 4 to Rails 5. In my Rails 4 version I have quiet_assets_path set but in Rails 5 it is not required. But when I removed that tried to start the server I am getting the following error,
> ruby-2.2.2/gems/rack-mini-profiler-0.10.2/lib/mini_profiler_rails/railtie.rb:93:in
> `>': comparison of Fixnum with nil failed (ArgumentError) from
> /Users/Admin/.rvm/gems/ruby-2.2.2/gems/rack-mini-profiler-0.10.2/lib/mini_profiler_rails/railtie.rb:93:in
> `block in <class:Railtie>'
Can someone help me with this?
Edit:
Following is my rack_profiler.rb,
if Rails.env.development? || Rails.env.production?
require 'rack-mini-profiler'
# initialization is skipped so trigger it
Rack::MiniProfilerRails.initialize!(Rails.application)
Rack::MiniProfiler.config.skip_schema_queries = true
Rack::MiniProfiler.config.skip_paths += %w(/admin/sidekiq)
Rails.application.middleware.delete(Rack::MiniProfiler)
Rails.application.middleware.insert_after(Rack::Deflater, Rack::MiniProfiler)
end
When I comment the delete line then server is starting but if the line uncommented then the server breaks.
thanks for the update. First of all, do you use Rack::Deflater middleware in development environment too?
I think this issue might help you. It basically says that in Rails all delete middleware operations are issued at the end. You can use the swap method as described in the above issue.
If you search the repo issues for "Deflater" you'll find a lot of results, but I believe the above contains your fix.

Devise Sign-Up Route End of File Reached Error

I've searched all over the internet for an answer to this error, but nothing seems to address it directly or effectively.
I am using Devise in a Rails application and whenever I go to the users/sign_up page and submit the data, it will not submit properly and Rails gives me the error:
"EOFError at /users
end of file reached"
Rails also includes this trace:
rbuf_fill/Users/john/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/net/protocol.rb
BUFSIZE = 1024 * 16
def rbuf_fill
begin
#rbuf << #io.read_nonblock(BUFSIZE)
rescue IO::WaitReadable
if IO.select([#io], nil, nil, #read_timeout)
retry
else
raise Net::ReadTimeout
Which I have had no luck following.
From other posts, I believe something may be wrong with the mailer setup, but I've tried every solution recommended and I'm still getting this error. Currently, I have config.mailer_sender = SUPPORT_EMAIL setup in the config/initializers/devise.rb file.
I would greatly appreciate any suggestions anyone has, as I've spent a ton of time on this with no luck.

RubyOnRails Rake test failures

i try to create internet shop from "Agile Web Development with Rails 4". When i write 'rake test', i get this message:
$ rake test
Run options: --seed 54737
# Running:
........F...F
Finished in 0.279167s, 46.5671 runs/s, 118.2088 assertions/s.
1) Failure:
ProductTest#test__product_is_not_valid_without_a_unique_title_-_i18n [/Users/roni/Coding/Ruby/depot/test/models/product_test.rb:82]:
--- expected
+++ actual
## -1 +1 ##
-["translation missing: en.activerecord.errors.messages.taken"]
+["has already been taken"]
2) Failure:
ProductTest#test_product_price_must_be_positive [/Users/roni/Coding/Ruby/depot/test/models/product_test.rb:25]:
Failed assertion, no message given.
13 runs, 33 assertions, 2 failures, 0 errors, 0 skips
It's product_test.rb
http://pastebin.com/1f5zkDwa
Please, help me, what i did wrong?
It appears the location of error messages for the 'already taken' case has been changed in Rails 4 and the book must have missed this update.
The error message has been moved to the namespace where also other validation error messages of ActiveModel reside, to the errors.messages. Hence, the 'taken' error message was set under key activerecord.errors.messages.taken, but in Rails 4 it is under errors.messages.taken.
If you update line 82 in your test with the new key, the test should pass.
Just like the message states, you don't have translation for en.activerecord.errors.messages.taken in config/locales.
Also, in assert_equal method, first argument is actual value, while second argument is expected value. So it should be:
assert_equal product.errors[:title], ["has already been taken"]
in this case.

Capybara issue when trying to click form submit button

I'm pretty new to Ruby/Rails and especially to Capybara and the whole process, so please bear with me as I've spent a lot of time on this already and I finally decided to ask because I'm sure it's something simple that I just am as-of-yet unaware of.
So I have a form that has several checkboxes that are designed to filter the results displayed (ie, you select one or more and submit and thew page reloads with the list filtered). In my features file, I have the following scenarios (the button to submit the form has a value="Refresh"):
Scenario: no ratings selected
When I uncheck the following ratings: G, PG, PG-13, NC-17, R
And I press "Refresh"
Then show me the page
And I should see none of the movies
Scenario: all ratings selected
When I check the following ratings: G, PG, PG-13, NC-17, R
And I press "Refresh"
Then show me the page
And I should see all of the movies
When I run this with rake features, it gives the following output:
And I press "Refresh" # features/step_definitions/web_steps.rb:61
xprop: unable to open display ''
I am using page.body a little later in the scenario and I believe this is the reason I then get the following errors:
Deprecated: please use #source_tags instead.
Warning: program returned non-zero exit code #1
WARNING: You don't seem to have any mimeinfo.cache files.
Try running the update-desktop-database command. If you
don't have this command you should install the
desktop-file-utils package. This package is available from
<link>
No applications found for mimetype: text/html
/usr/bin/xdg-open: 563: links2: not found
/usr/bin/xdg-open: 563: links: not found
/usr/bin/xdg-open: 563: lynx: not found
Error occured while reset 800b: errno=5
xdg-open: no method available for opening '/home/ubuntu/hw3_rottenpotatoes/tmp/capybara /capybara-201203260037535403047955.html'
Error occured: errno=5
Warning: program returned non-zero exit code #1
WARNING: You don't seem to have any mimeinfo.cache files.
Try running the update-desktop-database command. If you
don't have this command you should install the
desktop-file-utils package. This package is available from
<link>
No applications found for mimetype: text/html
/usr/bin/xdg-open: 563: links2: not found
/usr/bin/xdg-open: 563: links: not found
/usr/bin/xdg-open: 563: lynx: not found
Error occured while reset 800b: errno=5
xdg-open: no method available for opening '/home/ubuntu/hw3_rottenpotatoes/tmp/capybara /capybara-201203260037534847572739.html'
Error occured: errno=5
Warning: program returned non-zero exit code #1
WARNING: You don't seem to have any mimeinfo.cache files.
Try running the update-desktop-database command. If you
don't have this command you should install the
desktop-file-utils package. This package is available from
<link>
No applications found for mimetype: text/html
/usr/bin/xdg-open: 563: links2: not found
/usr/bin/xdg-open: 563: links: not found
/usr/bin/xdg-open: 563: lynx: not found
Error occured while reset 800b: errno=5
xdg-open: no method available for opening '/home/ubuntu/hw3_rottenpotatoes/tmp/capybara /capybara-20120326003754980186501.html'
Here are the relevant step definitions
When /I (un)?check the following ratings: (.*)/ do |unc, rating_list|
rating_list.split(", ").each do |r|
if(unc)
uncheck("ratings_#{r}")
else
check("ratings_#{r}")
end
end
assert true, "Implemented checking function"
end
Then /I should (not )?see movies with the following ratings: (.*)/ do |nt, rating_list|
flag = true
rating_list.split(", ").each do |r|
if(nt)
if(page.body =~ /<td>#{r}/)
flag = false;
end
else
if(page.body !~ /<td>#{r}/)
flag = false
end
end
end
assert flag, "Seeing (or not) movies of ratings list - implemented"
end
Then /I should see all of the movies/ do
tot = Movie.all.count
assert page.have_selector('tbody tr', :count => tot)
end
Then /I should see none of the movies/ do
num = page.body.scan(/00:00:00 UTC/m).length
assert size == 0, "Showing no movies - implemented"
end
When /^(?:|I )press "([^"]*)"$/ do |button|
click_button(button)
end
Then /^show me the page$/ do
save_and_open_page
end
I have been researching for days when I have time and there is just so much I don't know. Any help or insights would be greatly appreciated. Thank you!
Your problem is that you don't have any browser installed to handle html files.
It seems you are using an headless server (without X) so your system is trying to find a suitable browser (one that can be run from the command line).
Take a look at Capybara drivers and choose an appropriate one.

Resources