How to get Spring to work?

Hi,

RubyMine EAP 138.2332 ; Ruby 2.1.2 ; Rails 4.1.6 ; Ubuntu 14.04

How do you get Spring to work?

This is what the RM Help Doc has to say:
When spring is installed, Spring appears in the list of pre-loaded servers in the default run/debug configurations for RSpec, Test::Unit/Shoulda/Minitest, and Cucumber.
It is important to note that there is no dedicated run/debug configuration for the Spring server. Spring server is launched by default.

I put " gem 'spring' " into my Gemfile and it installed correctly.

SUB-QUESTION: The Rails doc says to put that statement in the 'development' section of the Gemfile. It seems to me that if you are going to use Spring for running tests that it should be in the 'test' section as well, should it not?

Regardless, I included the "gem spring" statement in both the 'development' and 'test' sections of the Gemfile.

I then ran the following command as per the RailsGuide instructions. Here is the command and its output:
larry@larry-lap:~/RubyMine/StupidTuesday$ bundle exec spring binstub --all
* bin/rake: spring inserted
* bin/rails: spring inserted

Then I went to the Run/Config section and for both RSpec and Cucumber for "Use pre-load server:" I selected "Spring". That seems to be working because when I select "None" my specs and cukes run fine and no mention is made of Spring.

However, when I try to run either RSpec or Cucumber I get the following error with the follwing output:
=======================================
ERROR: Test framework quit unexpectedly

Testing started at 10:01 AM ...
Version: 1.1.3

Usage: spring COMMAND [ARGS]

Commands for spring itself:

  binstub         Generate spring based binstubs. Use --all to generate a binstub for all known commands.
  help            Print available commands.
  status          Show current status.
  stop            Stop all spring processes for this project.

Commands for your application:

  rails           Run a rails command. The following sub commands will use spring: console, runner, generate, destroy.
  rake            Runs the rake command

Process finished with exit code 0
=======================================

Can someone tell me what I am doing wrong? (And also if the "gem spring" should appear in just 'development' or both 'development' and 'test' in the Gemfile.)

Thanks,
Larry

10 comments

in Rails 4.1 and up Spring is included by default

0

Hi,

I wrote a bunch of stuff here that was all "noise". I don't see how to delete it, so I'm just writing this. Please move on to my next post.

Thanks,
Larry

0

Hello again,

Obviously I'm confused about this, as oftentimes seems to happen when something is "automagically" done for us in Ruby and Rails.

After thinking about this, are the following assumptions correct?

I should *not* add "gem spring" to my Gemfile.
I should *not* "springify" the bin/rake and bin/rails commands.
I should *not* select "Spring" in the "Use pre-load server" in the Run/Config setup for both RSpec and Cucumber; I should just leave it as "None"

In other words, I should *not* do anything in order to use Spring because it's all being done automagically for me because I'm using Rails 4.1.6.

Is this correct?

Also, is Spring just used when running tests? I'm also confused about this becuase, as I stated in my first post, the Spring doc says to add "gem spring" to the 'development' section in the Gemfile.

If Spring is being used in both Development and Test modes, what about something like Delayed Job? Are you supposed to kill and re-start workers if you make changes to the code, or does Spring handle that as well?

Thanks (and sorry for being confused),
Larry

0

yes it's correct no need to add spring in gemfile and configs.
For delayed_job and in some other contexts i usually give spring stop, it's not a perfect technology
;)

0

Hi,

to run tests you need to add more gems :(
See https://github.com/rails/spring#additional-commands for more information

Regards, Oleg.

0

Hi Oleg,

Thanks for your reply.

I hate to sound stupid about this, but is putting the following commands in the ":development" section of the Gemfile the only thing I have to do in order for this to work?
gem 'spring-commands-rspec'
gem 'spring-commands-cucumber'

The documentation about these 2 gems says nothing more than one should include them in the Gemfile. But it just seems weird that testing gems should be placed in the ":development" section.

BTW, I am using Rails 4.x

Thanks,
Larry

0

Hi,

as far as I can see this is all you need.  I agree that it is strange to have such gems in :development env, but spring itself is also in this evn, and if you need more information
I think you should ask spring's developers ;)

Regards, Oleg.

0

Okay. Thanks for the quick reply, Oleg. I appreciate it because I know you guys must
always be busy.

-- Larry

0

Short info for others hitting this thread: Reading http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#spring it sounds as if you indeed need to add the 'spring' gem to the Gemfile for Rails 4.1 and later as well.

0

Please sign in to leave a comment.