Where is the .rspec configuration file located exactly? - ruby-on-rails

Working through the Ruby on Rails Tutorial and stuck here "To run RSpec and Spork with Autotest, we need to configure RSpec to use the --drb option by default, which we can arrange by adding it to the .rspec configuration file in the Rails root directory (Listing 3.14)."
When I search my file structure I can not find a single file with .rspec file extension? How do I access this file to update the configuration?

If you are using a mac you will not see these files just like you will not see the gitignore file
what you need to do in order to access this file is from the root directory of the app just click (command line)
mate .rspec
this will open the file if it's there, and if not, it will create it.

If you add gem 'rspec-rails' to your Gemfile, you can use the rails g rspec:install command.
This will create the .rspec file in the root of the Rails application. It will also create a spec folder and a file inside it 'spec_helper.rb'
If you do not want to write this command, you may simply create the file manually. If you are using a linux machine, the hidden files can be seen with a <ctrl-h> command. You may also try the ls -a in any unix terminal to see all hidden and non hidden files.

Files on mac that begin with . are not shown by default. In Terminal, if you type ls -a you'll see all of the "dotfiles" that are in the folder.
If this file doesn't exist yet (it probably doesn't) then you just need to create it using your favorite editor.

Related

Trying to open .gitignore to edit it in text editor but cannot find location of file on OS X Mountain Lion

I created a new rails app using "new app_name" and I'm trying to edit the .gitignore file but can't find it in my app folder. Where can I find it? I have Git installed.
.gitignore is in the root of the project, not in the app subdirectory. First open the terminal and go inside your directory.
You'll need to use ls -a to show hidden files.
Then use open .gitignore
Dotfiles are hidden. Use ls -a to see it.

its about what to do if you didn't install sublime when using ruby on rails tutorial

I did not install sublime. I'm at the point in the Ruby on Rails Tutorial by Hartl where he has you set up a branch for the first time. So I can't figure out what to do where his instructions are
$ git mv README.rdoc README.md
$ subl README.md
Should I create a file like the one in his book and then replace the original README.rdoc document and skip these commands? Should I create the new README.md file and put it in the main project folder but keep leave the old file there? If I do one of these can I then just continue with the rest of the commands after these? Should I do one of the above and then run just the first command above? The book doesn't seem to give a clue really about what is necessary here. It doesn't even actually tell you to create the new file. Honestly I'm lost here.
The only thing I think I understand is that the first command above renames the old file. If that is true then can I just run that command and then edit the original file in a text editor. Would I then skip the second command. Could I then continue with the rest of the commands.
By the way I working on a laptop running Windows 7.
$ git mv README.rdoc README.md
That is going to rename the file. Nothing more.
$ subl README.md
That is going to open the renamed file in Sublime (a text editor).
If you want to achieve those two steps, just rename the file however you like and open the file in any text editor.

Ruby on Rails Tutorial - 5.26 - Sublime Text "Unable to Save" new file "spec/support/utilities.rb"

I am using Sublime Text 2 while following Michael Hartl's Ruby on Rails Tutorial.
The specific portion of the tutorial to which I am referring can be found at http://ruby.railstutorial.org/book/ruby-on-rails-tutorial (ctrl+F "Listing 5.26").
I am able to create the spec/support file. However, when trying to create the spec/support/utilities.rb file, I receive the message "Unable to save ~/rails_projects/sample_app/spec/support/utilities.rb".
Does anyone know why this might be?
Someone on the Sublime Text forum seems to have had the exact same problem: http://www.sublimetext.com/forum/viewtopic.php?f=3&t=8570&p=36922#p36922
This issue sounds like it's a result of incorrect permissions or ownership of the folder. Change directories (cd) so you're outside of the folder where you're creating the .rb file and type:
ls -l
This terminal command lists the permissions attached to all files/folders in that directory. If "root" is listed as the folder owner, change its owner by typing:
sudo chown YOUR_COMP_USER_NAME FOLDER_NAME/
You should now be able to save files from inside that folder.
To diagnose this, first find out if it's an issue in Sublime or your file system:
Does that file already exist? Try looking for it on your file system (not using Sublime).
Verify that you have permission to write to that file. Use "ls -la" on the command line to show the file permissions.
Are you able to create and/or save that file using any different editor, for example TextMate, or Notepad?
The following sublime plugin fixed the Unable to save... bug
https://gist.github.com/3779601
The folder spec/support doesn't exist, and sublime won't create the missing folder, so it errors.
You just need to make the spec/support folder , then sublime will save the file.
I also highly recommend installing the AdvancedNewFile plugin ( Video of it action thanks to Jeffrey Way and NetTuts+ ) , which you can grab straight from Package Control.
It creates files, parent folders if needed, and if you try to create a file that already exists, it opens it instead.
This can happen if you are trying to create the file within a directory that does not currently exist. For ex. I was unable to save
~/rails_projects/sample_app/app/views/shared/_error_messages.html.erb
via the "subl" command from the Terminal because I was missing /shared/ folder. Hope that helps.
so #knice almost had it, I ran into the same problem with permission when starting my first rails project on mavericks.
as mentioned if you run ls -l you'll see your folder / files listed with their permissions
I solved this by changing ownership recursively with the following command from outside my project directory
sudo chown -Rv <your_username> <your_path_and_foldername>
for example if you're in your folder in terminal you should cd .. and then
sudo chown -Rv username ruby_proj/
the -R is for recursive meaning it will apply to all files and folder contained within the folder you specified, and the v after just produces verbose output, showing you which folder and file permissions have been changed.
Hope that helps someone else.

Opening a db/migrate/* file more effectively? Wildcard to complete the beginning of the name of the file?

Working from a bash shell and utilizing vim, I generally have a pretty effective workflow. However, when I attempt to access files in the db/migrate directory of a rails project, it becomes very tedious to access the files as the each contain a long integer at the being of their file names. I've tried vim db/migrate/*name_of_migration.rb but to no avail.
Is there a way to access files via wildcard of in this manor?
If you're using vim-7.3, then you can do this from inside vim:
:set path=/path/to/your/project/root/**
:find migrate/*cr<tab>
and vim will show you the possible candidates for completion.
If you're typing the name of the migration correctly, I assure you that the * will match the leading digits.
For example, from the root of your project,
$ vim db/migrate/*create_users.rb
will open 20111123142812_create_users.rb.
Otherwise, my preferred method is to use
$ vim db/migrate
to "open" the directory in vim, and use the in-vim navigator to select the migration you're interested in from the list of files.

.gemrc file specification

I searched everywhere to find the .gemrc file specification but I haven't succeed.
Does anyone know where I can find it?
gem looks for a configuration file .gemrc in your home directory, although you can specify another file on the command-line if you wish (with the --config-file modifier).
There are three things you can specify in the configuration file:
command-line arguments to be used every time gem runs
command-line options for ’’RDoc’’ (used when generating documentation)
GEM_PATH settings
More at gem environment command doc.
'Home' is a Linux/Mac term. What is refers to is the folder where a user's settings appear. You can find out where your settings directory is by doing the following:
on Unix/Linux, open a terminal and type the following command:
echo $HOME
on Windows, open a command-prompt and type the following command:
echo %USERPROFILE%
For me (in Windows 7), this is C:\Users[name]. However, looks like Ruby doesn't set up your .gemrc in that folder by default. Instead, you have to create the file. Open a text editor, copy the YAML style code you need (documentation), and save the file as .gemrc in your home directory (make sure you select all files, not '.txt').
These settings will only affect that individual user. If it's your personal computer, however, you probably don't need to change the settings for all users.
An updated gemrc specification is available at RubyGems Guides (under 'gem environment'). Note that /etc/gemrc applies to all users, while ~/.gemrc applies to an individual.
If the key is a gem command (for example, install:), it specifies arguments to be used with that command.
Here are the other keys that can be specified:
:sources: A YAML array of remote gem repositories to install gems from
:verbose: Verbosity of the gem command. false, true, and :really are the levels
:update_sources: Enable/disable automatic updating of repository metadata
:backtrace: Print backtrace when RubyGems encounters an error
:gempath: The paths in which to look for gems
All of the answers here at time of writing are wrong because the obnoxious website keeps changing. It is at this moment here:
https://guides.rubygems.org/command-reference/#gem-environment
Obviously you should expect it to change constantly at this point.

Resources