I am learning rails by following the Rails Tutorial under Ubuntu. I have been using spork and autotest and following the TDD as suggested by the book.
At some point (which I can't tell) the autotest stopped refreshing on it's own and so I killed it, alongside spork to reboot them both (the book does say that happens and that you should reboot them) just like I had done couple of times before.
This time spork won't load and give me this error: "I can't find any testing frameworks to use. Are you running me from a project directory?" and there doesn't seem to be any documentation whatsoever.
What could it be?
P.S. I am running it from the project directory. I already tried the bundle install and bundle update commands, I also uninstalled the spork gem with gem uninstall spork and reinstalled it with bundler... nothing (Rebooting the computer does nothing as well XD).
I am using "RSpec" to run the test alongside "autotest". It seems that at some point I accidentally removed the rspec_helper.rb file (or something like that, I can't really recall the name of the file) and that was keeping both "spork" and "autotest" off.
Just had to re-run the generate scripts for RSpec and voilĂ . All worked like a charm.
P.S.: For sanity run your generate script in a project copy for the the generate script could replace some other files and brake some custom-made functionality.
Related
I have a perplexing issue here when trying to implement the Rails Webpacker gem into an existing application.
Unfortunately, I do not have much to offer in the way of debugging information, this is also an internal project, so I have limited options in terms of sharing the entire project source.
I am following the exact steps outlined here: https://github.com/rails/webpacker and have done it multiple times now, but during the bundle exec rails webpacker:install command (after running bundle), I see the message:
Skipped webpack and webpack-dev-server since they already exist.
If you want to overwrite skipped stubs, use --force.
This binstubs most-definitely do not exist in my bin/ directory. Either before or after the webpacker install.
I feel like I have tried everything at this point, and nothing seems to be working:
Reinstalling the gem (multiple versions, even via Git)
Manually creating the binstub from a different project (this "worked" until I tried to run the webpacker:install:react script).
Manually running Yarn, attempting to --force create the binstubs
Tried multiple different configuration tweaks in webpacker.yml
I am just out of ideas at this point. Anything else I should be checking, could try?
This is a fix that worked for me:
I copied these two files into the bin directory of my app and then bundle exec rails webpacker:check_binstubs stopped complaining.
As a side effect it made my app deployable on my Paas with the standard buildpack.
When I run a rails console using
rails console
everything is fine.
When I run a rails console using
bundle exec rails console
I get the following warning
Bundler is using a binstub that was created for a different gem.
This is deprecated, in future versions you may need to `bundle binstub my_gem` to work around a system/bundle conflict.
my_gem happens to be a gem that I've created that is completely unrelated and not used in the current project directory.
I've tried every solution in this question with no luck:
Bundler is using a binstub that was created for a different gem
I would appreciate any guidance on removing this warning or help understanding how binstubs work so that I can figure out what's going on.
Nowadays it's common for projects to have "specialized" versions of tools. E.g. in some projects the "rails" command may be expected to be run using "spring" (to start up faster).
So it's not uncommon to generate files in your project's 'bin' directory, and then use those versions when running commands, so e.g. instead of
bundle exec rails console
or
bundle exec spring rails console
you could simply expect the following to work correctly
bin/rails console
and not care whether the project needs spring or bundler or zeus or whatever.
So if you don't have 'bin/rails' in your project, you should generate one that suits the project, e.g. using
bin/rake rails:update:bin
If you don't already have bin/rake, you might have to use
bundle exec rake rails:update:bin
(so your bin/rake commands will also get a speedup from using spring)
Some people even put ./bin in their paths, so whenever they run rake (or whatever) they are actually running ./bin/rake if it exists.
Troubleshooting
for project specific tasks, use bin/* files, creating them if needed (e.g. using special rake tasks like in Rails or using bundle binstub <gemname>) - usually those have Bundler specific lines that will make Bundler happy.
for non-project gems (like your gem), find out where it is (e.g. which mygem) and check out it's contents - it's probably using e.g. "bundler/setup" which is confusing Bundler (because bundler expects a local Gemfile file). Maybe your gem is using bundler (it shouldn't if it's a "global" kind of tool and not a "project" tool).
Also, if you're using them, check if tools like RVM and .rbenv are correctly adding their stuff to your bin files (they usually need to setup specific paths)
If you still have questions, it's best to post the contents of the bin file causing problems - it's meant to be a plain Ruby file, so if there's something wrong, it's usually because of the file contents (and not anything else).
More info: https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs
It happened in a project of mine. Because I ran bundle install with another ruby version.
Make sure your rvm is the correctly ruby version.
I followed the rails tutorial to install Spork and Guard:
http://ruby.railstutorial.org/chapters/static-pages?version=3.2#sec:first_tests
Guard and Spork work when started separately, but when using it together, it hangs with the last output line "Spork is ready and listening on 8989!" without executing any tests.
I even used the argument :wait => 60 as described on https://github.com/guard/guard-spork
Any idea?
And by the way, if I should post the Gemfile or the Guardfile, is there any way to paste it without manually indenting each line by 4 spaces?
Thanks
You should be able to use the " blockquote or {} codeblock buttons to automatically highlight or indent.
Setting up my tests gave me some trouble too as I followed along with the same tutorial. I got lucky by looking for other tutorials (some are listed below) and playing around with different gems and gem versions. Some things I learned the hard way in playing around with gem versions:
1) Calling "guard" from your project directory and calling "bundle exec guard" may or may not execute the same version of the guard gem, if you have more than one version installed. I recommend reading about bundler if you suspect gem versions might be giving you trouble. I know they gave me trouble.
2) The definitive version of the gem you are using for your project is listed in Gemfile.lock, but you're not supposed to modify that file. Modify the Gemfile with specific gem versions to get the right version installed.
Type One Error,
The Carbon Emitter
I hope you realize that when you first start guard and spork together it isn't supposed to execute any tests? It waits until you change a file, and then runs the tests for that file that changed. Or if you want it to run all specs, just hit your key.
As an example, I want to download: https://github.com/banker/newsmonger and tinker with it (to learn Rails). I've downloaded the zip and when I go into that folder and type rails server, the terminal window says to create a new rails app
This is a Rails 2 application, and so as ennuikiller said, you'll need to run script/server.
You may run into problems with dependencies not being installed in this application, which is a problem that normally (now) would be solved with Bundler. Due to this being a Rails 2 application, it doesn't support Bundler out of the box and the owner of the repo hasn't updated it to support that, and so you're dead outta luck there.
What you'll need to do is attempt to run rake gems:install (which may or may not work, depending on the sun's positioning) which will install the gems specified in config/environment.rb and the proper config/environments files using the config.gem methodology. This was how it was done in Rails 2, and caused so many problems that Bundler was created.
If that doesn't work, contact that banker guy on GitHub and ask him what the deps are or work out the dependencies yourself.
Good luck!
Depending on the version of rails this app uses you may have to execute the following :
script/server
I'm creating a few gems by extracting out parts of a Rails project that can be reused (and that I have duplicated in other Rails projects). The problem I have is that testing every change to the gems is now very slow.
Changing a Rails project is very fast as most of the time the change is re-loaded automatically, but changing a gem implies:
stop the rails server
go to the gem directory
run sudo rake install, which is very slow
go back to the rails project
re-run the rails server, which also is very slow
Is there a way for my Rails project to pick up the code from where I have the gem code, instead of the installed gem, to speed up development?
You could run rake gems:unpack to unpack the installed gem into the vendor/gems directory, then make your edits there.
If you want to keep your code where it is, you can symlink from vendor/gems to it. It'll give you warning and it'll be nasty, but it'll work.