Re: Running sinatra from RubyMine: exits immediately

464 views
Skip to first unread message

kedar mhaswade

unread,
Apr 11, 2013, 9:09:02 AM4/11/13
to sina...@googlegroups.com
This is perhaps Windows-specific. On my Ubuntu, "running a sinatra app in a file, say s.rb" by choosing the menu option Run -> Run 's' or Run -> Debug 's' works as expected; the command line issued by RubyMine is 
/path/to/ruby-1.9.3-p392/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /tmp/s/s.rb

I somehow suspect that the cleaned_caller or caller_files method in base.rb needs some overhaul, but I am not sure. This is because the app_file being returned with a -e.

If you undo your modifications to Sinatra and just add 
puts Sinatra::Application.app_file

before your get '/hi' block and run the app (Run menu -> Run) what does it print on the console?
(In both Run and Debug cases, you should see the full path of the file on disk that contains your application code).


On Wed, Apr 10, 2013 at 3:57 PM, <jennek...@oce.com> wrote:
Hi,

I just started exploring sinatra. So I entered the well known
    require 'sinatra'
    get '/hi' do
        "Hello World!"
    end
and ran this from within RubyMine. This resulted in this console message

C:\rubies\ruby193\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/Users/jennek/ruby/sinatra.rb
Process finished with exit code 0

I found out that this line in ..../gems/sinatra-1.4.2/lib/sinatra/main.rb may be the cause (line 12)
    set :run, Proc.new { File.expand_path($0) == File.expand_path(app_file) }
because it turns out that
    File.expand_path($0) == C:/Users/jennek/ruby/sinatra.rb
    File.expand_path(app_file) == C:/Users/jennek/ruby/-e
and patching the line like this
    set :run, true # Proc.new { File.expand_path($0) == File.expand_path(app_file) }
makes sinatra run as expected
    == Sinatra/1.4.2 has taken the stage on 4567 for development with backup from Thin

So it seems that the RubyMine -e command line argument interferes somehow.
Indeed removing the -e argument from the RubyMine configuration makes sinatra run as expected too.

However, both the main.rb patch and the configuration change are workarounds.

Is there another way to make sinatra run properly under RubyMine?
Am I missing something?

Thanks
-jennek

--
You received this message because you are subscribed to the Google Groups "sinatrarb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sinatrarb+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Konstantin Haase

unread,
Apr 11, 2013, 9:30:21 AM4/11/13
to sina...@googlegroups.com
As a quick fix, you could also do `set :app_file, __FILE__` in the file.

Unfortunately I have neither RubyMine nor Windows available at the moment to reproduce this.

Konstantin

kedar mhaswade

unread,
Apr 11, 2013, 12:50:57 PM4/11/13
to sina...@googlegroups.com
That fix should work, but I don't think it is needed. I just ran the vanilla Sinatra 1.4.2 app without any problems on Windows 7 with RubyMine 5 and Ruby 1.9.3 (and WEBrick). So, jennek, I am not sure what problems you are running into.

jennek...@oce.com

unread,
Apr 11, 2013, 7:42:58 PM4/11/13
to sina...@googlegroups.com
Thanks for the quick replies!

    puts Sinatra::Application.app_file
results in 
    -e
which is consistent with my earlier findings.

Adding 
    set :app_file, __FILE__
to my sinatra.rb forces sinatra to run as expected
As a workaround, I prefer this to patching the gem.

That's good enough for now, only exploring at this stage.

Is this something I should put on the issues list on github?

Thanks
-jennek 

Reply all
Reply to author
Forward
0 new messages