DRb::DRbServerNotFound passing Sinatra params - ruby

I have a Sinatra application and DRb server object paired. When I try to pass the Sinatra params hash to a method on my server object I get DRb::DRbConnError …
DRb::DRbServerNotFound, yet the same method works when I pass a simple hash directly.
Why am I getting this error with the Sinatra params hash?
What are the easiest and most correct workarounds to fix this problem?
Here's a simple test case:
# server.rb
require 'drb'
class Server; def echo( hash ); hash; end; end
DRb.start_service 'druby://localhost:9007', Server.new
DRb.thread.join
# app.rb
require 'sinatra'
require 'drb'
SERVER = DRbObject.new_with_uri 'druby://localhost:9007'
get("/params"){ SERVER.echo(params).inspect }
get("/hash" ){ SERVER.echo(hello:'world').inspect }
With both of these running in their own processes:
phrogz$ curl http://localhost:4567/hash
{:hello=>"world"}
phrogz$ curl http://localhost:4567/params
DRb::DRbConnError - DRb::DRbServerNotFound:
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1653:in `current_server'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1721:in `to_id'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1050:in `initialize'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:642:in `new'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:642:in `make_proxy'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:559:in `rescue in dump'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:556:in `dump'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:603:in `block in send_request'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:602:in `each'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:602:in `send_request'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:903:in `send_request'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1196:in `send_message'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1088:in `block (2 levels) in method_missing'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1172:in `open'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1087:in `block in method_missing'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1105:in `with_friend'
/usr/local/lib/ruby/1.9.1/drb/drb.rb:1086:in `method_missing'
app.rb:4:in `block in <main>'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1152:in `call'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1152:in `block in compile!'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:724:in `instance_eval'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:724:in `route_eval'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:708:in `block (2 levels) in route!'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:758:in `block in process_route'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:755:in `catch'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:755:in `process_route'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:707:in `block in route!'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:706:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:706:in `route!'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:843:in `dispatch!'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:644:in `block in call!'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:808:in `instance_eval'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:808:in `block in invoke'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:808:in `catch'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:808:in `invoke'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:644:in `call!'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:629:in `call'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.2/lib/rack/head.rb:9:in `call'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.2/lib/rack/commonlogger.rb:18:in `call'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/showexceptions.rb:21:in `call'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.2/lib/rack/methodoverride.rb:24:in `call'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1272:in `block in call'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1303:in `synchronize'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1272:in `call'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.2/lib/rack/content_length.rb:13:in `call'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.2/lib/rack/chunked.rb:15:in `call'
/usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.11/lib/thin/connection.rb:84:in `block in pre_process'
/usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.11/lib/thin/connection.rb:82:in `catch'
/usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.11/lib/thin/connection.rb:82:in `pre_process'
/usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.11/lib/thin/connection.rb:57:in `process'
/usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.11/lib/thin/connection.rb:42:in `receive_data'
/usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
/usr/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
/usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.11/lib/thin/backends/base.rb:61:in `start'
/usr/local/lib/ruby/gems/1.9.1/gems/thin-1.2.11/lib/thin/server.rb:159:in `start'
/usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.2/lib/rack/handler/thin.rb:14:in `run'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1234:in `run!'
/usr/local/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/main.rb:25:in `block in <module:Sinatra>'
This is running under Ruby 1.9.2 on OS X, not that I think it makes a difference.

Short answer
You need to add
DRb.start_service
to app.rb before you try to make a remote call.
Explanation if you're interested
The Sinatra params hash is created with an associated block to handle the case when missing keys are referenced (here's the source). This means there's a Proc object associated with it.
Drb passes arguments back and forth by Marshalling them. However, from the Marshal docs:
Some objects cannot be dumped: if the objects to be dumped include bindings, procedure or method objects, instances of class IO, or singleton objects, a TypeError will be raised.
So there's going to be problems trying to pass this params hash about over the wire, as it contains an unmarshallable procedure object.
Now onto the Drb docs:
However, if an object cannot be marshalled, a dRuby reference to it is passed or returned instead. This will turn up at the remote end as a DRbObject instance. All methods invoked upon this remote proxy are forwarded to the local object, as described in the discussion of DRbObjects. This has semantics similar to the normal Ruby pass-by-reference.
Good news, it should still work. So what's wrong? A bit further on in the Drb docs we find this in the example code:
# Start a local DRbServer to handle callbacks.
#
# Not necessary for this small example, but will be required
# as soon as we pass a non-marshallable object as an argument
# to a dRuby call.
DRb.start_service
So what appears to be happening is Drb is trying to get a remote reference for the procedure object to pass to the server, but is unable as there's no Drb service set up client side.
Original answer
(I'll leave this here, it might me of interest. It was a resting point on my journey to figuring it all out. It's also a possible alternate solution. Interestingly, it appears that I'm now the more knowledgable person I referred to, at least with respect to the why.)
Here's a possible workaround. The problem seems to be with hashes created with a block to deal with missing keys (which Sinatra's params hash is), so you could extract the contents of the hash into a new one. params.clone and params.merge({}) both appear to retain the proc (you can check with Hash#default_proc), but {}.merge(params) (or merge!) gives you a nice clean hash that works with Drb.
So, in this example, do this:
get("/params"){ SERVER.echo({}.merge params).inspect
Why this happens with Drb and hashes with procs, and whether this is the easiest or most correct workaround, I'll leave to someone more knowledgable.

Related

Ruby Pry locate test file that triggered pry

I have a block of code that triggers my pry session via an integration test but no unit test exists. As such I'm not sure which test is exercising this code and need to run all tests each time I want it to trigger. Is there a way, in a pry session, to bubble up the test/test file? I do not need the _file_ that triggered the pry session.
My best solution has been to raise errors while in the pry session and then continue the test suite hoping that'll flub up a test and be able to locate that test in the testing report. This approach is a bit too much like stabbing in the dark.
You should be able to get the full call stack by simply invoking caller:
$ pry
[1] pry(main)> caller
=> ["/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:290:in `eval'",
"/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:290:in `evaluate_ruby'",
"/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:659:in `handle_line'",
"/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:261:in `block (2 levels) in eval'",
"/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:260:in `catch'",
"/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:260:in `block in eval'",
"/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:259:in `catch'",
"/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:259:in `eval'",
"/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:77:in `block in repl'",
"/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:67:in `loop'",
"/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:67:in `repl'",
"/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:38:in `block in start'",
"/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/input_lock.rb:61:in `__with_ownership'",
"/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/input_lock.rb:78:in `with_ownership'",
"/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:38:in `start'",
"/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:15:in `start'",
"/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/pry_class.rb:191:in `start'",
"/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/lib/pry/cli.rb:119:in `start'",
"/home/john/.gem/ruby/2.7.0/gems/pry-0.13.1/bin/pry:13:in `<top (required)>'",
"/home/john/.gem/ruby/2.7.0/bin/pry:23:in `load'",
"/home/john/.gem/ruby/2.7.0/bin/pry:23:in `<main>'"]

HTTP request path is empty (ArgumentError)

I am new to ruby programming. This is my first program in Watir. When I execute the code below, I am getting HTTP request path is empty (ArgumentError). Appreciate your help in fixing this error. I am accessing internet through proxy settings. I have added HTTP_PROXY variable in environment variables to http://myproxy.mynetwork.net:8008/
test.rb
require "watir"
require "rubygems"
require "rspec"
require "watir-webdriver"
puts "Hello,World...!"
#browser = Watir::Browser.new
#browser.goto("http://www.google.com")
#browser.close
puts "Browser should have been closed.."
Output
d:\>ruby test.rb
Hello,World...!
C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1860:in `initialize': HTTP request path is
empty (ArgumentError)
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:2093:in `initialize'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/remote/http/default.rb:71:in `new'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/remote/http/default.rb:71:in `new_request_for'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/remote/http/default.rb:35:in `request'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/remote/http/default.rb:64:in `request'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/remote/http/common.rb:40:in `call'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/remote/bridge.rb:634:in `raw_execute'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/remote/bridge.rb:99:in `create_session'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/remote/bridge.rb:68:in `initialize'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/firefox/bridge.rb:36:in `initialize'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/common/driver.rb:31:in `new'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/common/driver.rb:31:in `for'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver.rb:67:in `for'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.9/lib/watir
-webdriver/browser.rb:46:in `initialize'
from test.rb:8:in `new'
from test.rb:8:in `<main>'
Firefox browser window is getting opened. After that the address bar is not changing, and it is getting closed after some time.
net/http require a valid path. So you have to put a trailing slash at the end of the URL, like this:
#browser.goto("http://www.google.com/")
I have added HTTP_PROXY variable in environment variables to
http://myproxy.mynetwork.net:8008/
Removing my HTTP_PROXY variable from my (Windows) user/system env settings helped!
am not sure why this is causing the issue with selenium..
The following steps helped me:
Remove HTTP_PROXY and HTTPS_PROXY variables from my system (User Variables)
Restarted my terminal for the changes to take effect.
That's about it! No more errors!

How do I use ruby to read the source a uri that im hosting on my own computer?

I trying to get ruby to read the source of a url thats being hosted on my own computer. I've tried using open-uri gem with:
source = open('http://127.0.0.1:8000/wikipedia_en_all_nopic_01_2012/A/Mick%20Jagger.html', &:read)
With normal external urls this works fine but it raises multiple errors when i try to access the url im hosting on my computer. Does anyone have any idea how to this? Heres the command line error report:
/Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/http/response.rb:357:in `finish': incorrect header check (Zlib::DataError)
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/http/response.rb:357:in `finish'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/http/response.rb:262:in `ensure in inflater'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/http/response.rb:262:in `inflater'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/http/response.rb:274:in `read_body_0'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/http/response.rb:201:in `read_body'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/open-uri.rb:328:in `block (2 levels) in open_http'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/http.rb:1415:in `block (2 levels) in transport_request'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/http/response.rb:162:in `reading_body'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/http.rb:1414:in `block in transport_request'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/http.rb:1405:in `catch'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/http.rb:1405:in `transport_request'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/http.rb:1378:in `request'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/open-uri.rb:319:in `block in open_http'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/http.rb:853:in `start'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/open-uri.rb:313:in `open_http'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/open-uri.rb:723:in `buffer_open'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/open-uri.rb:210:in `block in open_loop'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/open-uri.rb:208:in `catch'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/open-uri.rb:208:in `open_loop'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/open-uri.rb:149:in `open_uri'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/open-uri.rb:703:in `open'
from /Users/rorycampbell/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/open-uri.rb:34:in `open'
from testurl.rb:6:in `<main>'
UPDATE: I'm using kiwix server to host the URL
Try using net/http instead.
require 'net/http'
source = Net::HTTP.get URI.parse('http://127.0.0.1:8000/wikipedia_en_all_nopic_01_2012/A/Mick%20Jagger.html')
Why do you want you use a URL if it's on the local machine? Why not just give the path?
That error sounds like there's something wrong with the actual file you're trying to parse, or the way it's being served by the way. From reading about Kiwix server it sounds like the latter...On the Kiwix site it says that it uses some type compression method called openzim which is most likely why open-uri can't find a way to parse it.
You could try nokogiri and see if it has a problem parsing it. But since it seems like you're trying to open/manipulate a zim file in ruby, I'd look for a zim library for ruby instead of trying to serve it.
Here:
https://github.com/chrisistuff/zim-ruby
I've never dealt with kiwix/zim, so I don't know if this one works but it was the only one the a google search for 'zim ruby' came back with.
I had the same problem with kiwix. I extracted all the URLs in a file called hrefs.txt (in my case it was the german project gutenberg) and used wget to download each of them:
f = File.open("hrefs.txt", "r")
f.each_line do |url|
#filename = url.split("/").last.gsub!(/[^A-Za-z]/, '')[0..-4]
system "wget #{url}"
end
f.close

Using `require 'classname'` causes "No such file to load -- Classname" error on Heroku

TLDR: Using require 'classname' in another model file (so I can deserialize a column) works locally but results in the No such file to load -- Classname error when deploying to Heroku.
I've made the admittedly poor design decision to serialize a model attribute which contains an array of another model's objects (UserCategoryQueue has a serialized queue of Card objects). In order to actually de-serialize these objects, I've followed the advice in YAML::load raises undefined class/module error to use require 'Card' in the files where I need to deserialize that column. That avoids the issue where YAML doesn't know what it's looking at when it gets to the Card object.
This works fine on the localhost server but has resulted in a lot of issues when deploying to Heroku, all of the form No such file to load -- Card". Initially, this occurred during the asset precompilation phase, then I precompiled the assets myself and the same error has moved to when I try to run $ heroku run rake db:migrate to get everything set up for the first time.
Sample Files:
# app/models/user_category_queue.rb
class UserCategoryQueue < ActiveRecord::Base
...
# Our queue of Cards
serialize :queue, Array
end
# app/models/quiz.rb
class Quiz < ActiveRecord::Base
...
require 'Card'
...
# grab a random card from the user's queues
# produces YAML error without the above require statement
def sample_card
self.user.user_category_queues.sample.queue.sample
end
end
This ultimately resulted in the following errors on pushing to Heroku (prior to any asset precompilation attempts on my part):
Running: rake assets:precompile
rake aborted!
No such file to load -- Card
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/app/models/quiz.rb:18:in `<class:Quiz>'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/app/models/quiz.rb:1:in `<top (required)>'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:329:in `require_or_load'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:288:in `depend_on'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:206:in `require_dependency'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:465:in `block (2 levels) in eager_load!'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:464:in `each'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:464:in `block in eager_load!'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:462:in `each'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:462:in `eager_load!'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:347:in `eager_load!'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application/finisher.rb:56:in `each'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application/finisher.rb:56:in `block in <module:Finisher>'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/config/environment.rb:5:in `<top (required)>'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:189:in `require_environment!'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:249:in `block in run_tasks_blocks'
/tmp/build_d0e6e2b8-a3fd-4a90-ae44-e703b0093401/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.0.0/lib/sprockets/rails/task.rb:54:in `block (2 levels) in define'
Tasks: TOP => environment
(See full trace by running task with --trace)
!
! Precompiling assets failed.
As I said, even when precompiling assets, though the push went fine, the ensuing database migration had the same error pop up.
Heroku runs a case-sensitive filesystem, whereas your OS may not be case-sensitive. Try changing that require to this instead:
require 'card'
As a general rule of thumb, most files within Ruby are required using lowercase letters with underscores serving as a word separator, like this:
require 'card_shuffler'

Cucumber Aruba trying to change directory results in a strange error

So I create the dotfiles directory and then cd to dotfiles. However, cucumber aruba is giving me an error that says dotfiles is not a directory. I can't figure out why this is? the code in pry results in the correct behavior.
#creation
Scenario: Create a dotfiles git repository
Given the directory dotfiles does not exist in the home directory
When I successfully run `dotfiles init dotfile_one dotfile_two dotfile_three`
Then a dotfiles directory should exist in the home directory
When I change directory to the dotfiles directory ### Fails here ###
Then a file named ".git" should exist
my steps
Given /^the directory dotfiles does not exist in the home directory$/ do
step %(a directory named "#{ENV['HOME']}/dotfiles" should not exist)
end
Then /^a dotfiles directory should exist in the home directory$/ do
step %(a directory named "#{ENV['HOME']}/dotfiles" should exist)
end
When /^I change directory to the dotfiles directory$/ do
step %(I cd to "#{ENV['HOME']}/dotfiles")
end
before hook:
Before('#creation') do
FileUtils.rm_rf(File.join(ENV['HOME'], 'dotfiles'))
end
the source
module Dotfiles
class Repository
def self.init(location, dotfiles)
# create the dotfiles directory and git init
FileUtils.chdir(location) do
FileUtils.mkdir_p(File.join location, 'dotfiles')
end
FileUtils.chdir(File.join location, 'dotfiles')
end
end
end
Short version of error
When I change directory to the dotfiles directory # features/step_definitions/aruba_steps.rb:13
tmp/aruba/Users/Brian/dotfiles is not a directory. (RuntimeError)
Here is the error with full trace
#creation
Scenario: Create a dotfiles git repository # features/dotfiles_repository.feature:6
Given the directory dotfiles does not exist in the home directory # features/step_definitions/aruba_steps.rb:5
When I successfully run `dotfiles init dotfile_one dotfile_two dotfile_three` # aruba-0.5.3/lib/aruba/cucumber.rb:71
Then a dotfiles directory should exist in the home directory # features/step_definitions/aruba_steps.rb:9
When I change directory to the dotfiles directory # features/step_definitions/aruba_steps.rb:13
tmp/aruba/Users/Brian/dotfiles is not a directory. (RuntimeError)
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/aruba-0.5.3/lib/aruba/api.rb:22:in `cd'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/aruba-0.5.3/lib/aruba/cucumber.rb:52:in `block in <top (required)>'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/core_ext/instance_exec.rb:48:in `instance_exec'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/core_ext/instance_exec.rb:48:in `block in cucumber_instance_exec'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/core_ext/instance_exec.rb:69:in `cucumber_run_with_backtrace_filtering'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/core_ext/instance_exec.rb:36:in `cucumber_instance_exec'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/rb_support/rb_step_definition.rb:97:in `invoke'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/step_match.rb:25:in `invoke'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:60:in `invoke'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/rb_support/rb_world.rb:52:in `step'
/Users/Brian/gems/dotfiles/features/step_definitions/aruba_steps.rb:14:in `block in <top (required)>'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/core_ext/instance_exec.rb:48:in `instance_exec'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/core_ext/instance_exec.rb:48:in `block in cucumber_instance_exec'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/core_ext/instance_exec.rb:69:in `cucumber_run_with_backtrace_filtering'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/core_ext/instance_exec.rb:36:in `cucumber_instance_exec'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/rb_support/rb_step_definition.rb:97:in `invoke'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/step_match.rb:25:in `invoke'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/step_invocation.rb:60:in `invoke'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/step_invocation.rb:38:in `accept'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:106:in `block in visit_step'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:105:in `visit_step'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/step_collection.rb:19:in `block in accept'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/step_collection.rb:18:in `each'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/step_collection.rb:18:in `accept'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:100:in `block in visit_steps'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:99:in `visit_steps'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:15:in `block in execute'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:82:in `block (2 levels) in with_hooks'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:98:in `before_and_after'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:81:in `block in with_hooks'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:120:in `call'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:120:in `block (3 levels) in around'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/language_support/language_methods.rb:9:in `block in around'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/language_support/language_methods.rb:97:in `call'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/language_support/language_methods.rb:97:in `execute_around'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/language_support/language_methods.rb:8:in `around'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:119:in `block (2 levels) in around'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:123:in `call'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:123:in `around'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:93:in `around'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:80:in `with_hooks'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:13:in `execute'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/scenario.rb:32:in `block in accept'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/scenario.rb:79:in `with_visitor'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/scenario.rb:31:in `accept'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:58:in `block in visit_feature_element'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:57:in `visit_feature_element'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/feature.rb:38:in `block in accept'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/feature.rb:37:in `each'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/feature.rb:37:in `accept'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:27:in `block in visit_feature'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:26:in `visit_feature'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/features.rb:28:in `block in accept'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/features.rb:17:in `each'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/features.rb:17:in `each'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/features.rb:27:in `accept'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:21:in `block in visit_features'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:20:in `visit_features'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:48:in `run!'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/cli/main.rb:47:in `execute!'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/bin/cucumber:13:in `<top (required)>'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/bin/cucumber:23:in `load'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/bin/cucumber:23:in `<main>'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `eval'
/Users/Brian/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `<main>'
features/dotfiles_repository.feature:10:in `When I change directory to the dotfiles directory'
Then a file named ".git" should exist # aruba-0.5.3/lib/aruba/cucumber.rb:264
Failing Scenarios:
cucumber features/dotfiles_repository.feature:6 # Scenario: Create a dotfiles git repository
1 scenario (1 failed)
5 steps (1 failed, 1 skipped, 3 passed)
0m0.631s
Anyone have any solutions or suggestions? Don't hesitate to ask if you have a question.
Thanks in advance
I see a couple things that I would do differently. There's no guarantee that this will make a difference, but it might.
dotfiles is never used in your code. 'dotfiles' is, so why do you require it as a parameter?
def self.init(location, dotfiles)
Ruby can interpret these lines two ways:
FileUtils.mkdir_p(File.join location, 'dotfiles')
FileUtils.chdir(File.join location, 'dotfiles')
Notice the difference in parenthesis to force parameter assignment in these lines:
FileUtils.mkdir_p(File.join(location), 'dotfiles')
FileUtils.mkdir_p(File.join(location, 'dotfiles'))
FileUtils.chdir(File.join(location), 'dotfiles')
FileUtils.chdir(File.join(location, 'dotfiles'))
Instead of writing your code like:
def self.init(location, dotfiles)
# create the dotfiles directory and git init
FileUtils.chdir(location) do
FileUtils.mkdir_p(File.join location, 'dotfiles')
end
FileUtils.chdir(File.join location, 'dotfiles')
end
I'd write it like this instead:
def self.init(location)
# create the dotfiles directory and git init
FileUtils.chdir(location) do
FileUtils.mkdir('dotfiles')
end
FileUtils.chdir('dotfiles')
end
Although Ruby allows us to not use parenthesis to surround parameters to a method, that is the source of untold many questions asked on Stack Overflow because code won't work. Parenthesis are important to the interpreter, to explicitely tell it what we really mean. When you don't use them, it will follow its normal order of operations and use rules of precendence to try to figure out what section of a line should be processed first, and without the parenthesis to force order of operation, it can make mistakes.
Our choice, at that point, is to either move the operation ahead of where we're going to use its result, or use parenthesis to make it clear what should happen when.
I just ran with a similiar problem. After a long time of investigation this line caught my attention:
tmp/aruba/Users/Brian/dotfiles is not a directory. (RuntimeError)
See how it begins with 'tmp/aruba'? Needless to say, my problem also had this 'tmp/aruba/' on it. If you look at the readme at github closely enough you will find out that aruba has a "working directory where it performs its file operations".
When I followed the instructions there I got it working alright!

Resources