Last week, my Cucumber tests started failing. All of them. Here is the error:
undefined method `split_stylesheet_link_tag' for #<#<Class:0x007ff9a433c390>:0x007ff9a6a848f8> (ActionView::Template::Error)
split_stylesheet_link_tag is a method I have from the css_splitter gem. It's found in my application.html.haml file. (Hence why all the tests are failing; they all use that main template.) Loading the view that the Cucumber test is trying to load works in development. In other words, this is only an issue in my test environment.
Here's where it gets weird. I was using RVM, and I had concluded it was an issue with my gemsets, because it's the gem that exposes that method. So I switched to rbenv, and ran the tests. They worked.
I'm not sure what I've changed in the meantime (I know, I know), but I'm getting that failure again. If you're interested in the backtrace, you can find it here.
What I've Tried
Googling around caused me to check the contents of .bundle/config. It contains
BUNDLE_DISABLE_SHARED_GEMS: '1'
That sounded like something that could be a culprit, so I changed that to 0 and ran bundle install. It changed it back to 1.
One interesting thing is that when I run bundle install in the root of this Rails app, I get this message:
Your bundle is complete!
It was installed into ./vendor/bundle
This didn't seem right.
I'm using rbenv-gemset. When I ran cat .rbenv-gemsets, I got global. So I followed the docs for rbenv-gemsets and changed global to .gems. The docs suggested that this would install the gems into the .gems directory in my project root. Running bundle install again gave me the same message about installing the gems into ./vendor/bundle, and there isn't a .gems directory in the root of my project. (I had assumed that adding .gems would create one.)
I'm using tmux, and wondering if that had something to do with it because of this issue, I tried running the tests outside of tmux and got the same error.
I've also made sure that my .bash_profile file contains eval "$(rbenv init -)" and that I've gone back through the rbenv setup. I've confirmed that both rbenv and its shims directory are on my path.
I made sure that css_splitter is in my Gemfile and is not nested under a group.
I'm sort of grasping at straws here. Just throw out any ideas.
This was apparently an issue with my bundler config. Gems were apparently being stored in the wrong directory. Based on this answer, I ran rm -rf ~/.bundle/ ~/.gem/ .bundle/ Gemfile.lock. Then I ran bundle install.
It's worth noting here that this also fixed the issue I was having with rbenv-gemset. That is, deleting those directories caused bundle install to install the gems into the .gems directory in this project as expected. That is, I'm guessing, why my test environment had access to the gems as expected.
Related
Bit of a strange question, but here goes.
I'm a relative beginner to rails, and I've just started working on my second app locally. However, after each install I'm getting the following problem - that several gemfiles are missing (railties being the most obvious).
So, I deleted the install, re-ran it and listed the gemfiles - they are all there. However, after initializing a git repo and pushing the project up to my GitHub a gem list command shows that a number of gems are now missing - at this point I can't run any rake commands or for example rails server.
So I cleared the repo and re-installed. gem list says the gems are all present, server and rake commands work; but push the repo and it subsequently packs up - gem list shows only a handful of gems remain.
Bearing in mind my experience, I'm prepared to believe I'm missing something very obvious, but any advice would be appreciated.
welcome ;-)
I suppose you want to create a Rails 3 application. So first make sure you have installed bundler.
gem install bundler
The steps for creating the application are:
rails new your_app
Then run bundler in the applications folder:
cd your_app
bundler install
Now you should be able to run the application:
rails s
Go and visit localhost:3000. If that does not work, you have other problems. Paste the stack trace then ...
The problem was I forgot that I had two versions of Ruby installed and I had not properly set a default with rvm for some reason. Specifying the default then checking the gems were present for that version of Ruby fixed it.
After installing RBEnv and rebuilding my ROR project, I now seem to have added many, many files to my project. They are in /vendor/local, and appear to duplicate what you would normally find in /Library/Ruby/Gems.
My project will not run without these files present (I get the message Could not find rake-0.9.2.2 in any of the sources.
I had difficulties with my RBEnv installation. I have what I suspect are other issues (like I have to bundle exec rails instead of just running rails). I suspect that I have done something wrong and should not have these files in my project. What I'd like to know is:
1) Should these files be there?
2) How best to fix this (if this is not how it is supposed to work)?
3) If the best approach is to start over and reinstall rbenv, how do I clear it all out?
It is true that using RBENV will end up putting copies of your gems in the project's /vendor/local folder. This is to remove any dependencies on your base gem set. These files need not be part of your source repository, as long as your 'gemfile' and your '.rbenv-version' file are included in the repository.
Another price you pay for using rbenv is that you must bundle exec rails <command> and bundle exec rake <command> from here on in.
I haven't upgrade my gems for a long time, just today, I decided to run a upgrade. I probably made a mistake at first running bundle install update, which didn't do anything. Then I ran bundle update, and it created a whole new folder called update in my rails directory containing all the gems, and it seems like my rails project is no longer linked to my rvm gem directory because if I remove the update folder it fuzzes about not being able to find gems. I'm just wondering if this is the new behavior to rails or it's because I did something wrong. Thanks!
Edit:
The output of bundle config is:
Settings are listed in order of priority. The top value will be used.
path
Set for your local app (/Users/X/dev/tasker/.bundle/config): "update"
disable_shared_gems
Set for your local app (/Users/X/dev/tasker/.bundle/config): "1"
This seems to be the problem. So how should I revert it to its state before by linking to the rvm gem directory? And is the problem caused by my 'bundle install update' command? Thanks!
Edit again:
Thanks for the help guys. After finding out the root issue of my problem, I found this solution: bundle install --system at How can I fix an accidental 'sudo bundle install dir_name'?. Now the problem is solved. Thanks!
I made same mistake.
Check command line options for bundle. bundle install accepts directory. and if you type bundle install update, it install the bundle onto the directory.
If you did, bundler create .bundle/config file and store the given path in the file.
I think, just removing .bundle directory and run "bundle" will bundle the needed files,
will use the gems in RVM (if RVM configured correctly).
I was trying to fix some garbage that was happening (frustratingly) by updating rubygems yesterday. To fix spork, I typed "bundle install spork" before I realized I hadn't actually typed "gem install spork" and it installed everything in a spork directory within my project folder. I removed that, and tried "bundle install ." which seemed to work. But I just went to do a commit and noticed I now had a ruby directory in my project.
I removed that, but now don't know how to get bundle to go back to installing somewhere outside my project directory. Does anyone know what command will accomplish this?
If you ever accidentally invoke bundle install foo then it will try to install your gems inside a foo directory, and also will set this as your permanent choice in .bundle. So, take a look at .bundle/config and make sure there isn't anything unwanted in there.
Needed to use bundle install --system to get it to revert back to the default directory.
bundle install with no path argument does it for me.
I have a Rails 3rc app on Ruby 1.9.2 that works fine, but Bundler keeps making a folder named "bandsintown" (bandsintown is a gem I use) in my project directory. From what I can tell, the folder has all my gems in it. I'm pretty sure that this never happened before. Is it normal behavior?
I think this might be interfering with running tests. I get a "Command failed with status (1)" error and then it mentions the "bandsintown" folder a few times.
I find it odd that Bundler names the folder "bandsintown" even when I comment out that gem in the gemfile. There's a "ruby" folder in that one, and a "1.9.1" folder inside the "ruby" folder. I don't understand why it says 1.9.1 when I'm using 1.9.2. The 1.9.1 folder has a bin, bundler, cache, doc, gems and specification folder inside of it.
I made a testapp with all the same gems and did a bundle install. It doesn't make a new folder with all my gems in it.
Anyway, my app works fine, but I'd appreciate it if anyone could help me out here. If I left out any need-to-know information, let me know. Thanks.
You are probably running the following command: bundle install bandsintown. That command tells bundler to install gems into the bandsintown subdirectory of your application. In order to install gems, all you need to do is modify your Gemfile and run bundle install.
Bundler will remember the location that you last specified in the .bundle/config file. So, in order to "reset" bundler's memory. In your application's directory, run rm -r .bundle/config.
Then, after updating your Gemfile, simply run bundle install