TDD in Ruby Course

Friday, April 24, 2015

NoMethodError: undefined method `devise' for User

 Problem: NoMethodError: undefined method `devise' for User (call 'User.connection' to establish a connection):Class
Solution:
 run rake db:migrate
before :
 rails g devise user

Check current environment in Sinatra

   if Sinatra::Base.development?
     # do something exciting here
   end

How to exclude spec folder from test coverage report

   SimpleCov.start do
     add_filter '/spec/'
   end

Reference

Sinatra TDD Tools   
 

Thursday, April 23, 2015

Upgrading Ruby using rbenv

1. Change the default version of Ruby globally to use 2.2.2

rbenv global 2.2.2

2. Change the ruby version in Gemfile

ruby '2.2.2'

3. gem install bundler

4. bundle


Wednesday, April 22, 2015

Sinatra Console

There is nothing similar to rails console in sinatra. You can go to irb and do a :

require './myapp.rb'

to start experimenting with your Sinatra app.

You can create a console.rb and put the following code:

require './game.rb'
require 'irb'
ARGV.clear
IRB.start

You now have a simple Sinatra console, you can run it as ruby console.rb.

Reference:

Sinatra Console

irb history

I installed ruby 2.2.1 using rbenv on Mac OS 10.10.3. By default the irb console does not save the history, so you cannot use the saved code in the history by using the arrows in new irb sessions. To fix this problem, create ~/.irbrc and add this code:

require 'irb/ext/save-history'
#History configuration
IRB.conf[:SAVE_HISTORY] = 1000
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"


Tuesday, April 21, 2015

Bundler is using a binstub that was created for a different gem.

This is an rvm issue. Suggestions on rvm home page did not work. Solution: Uninstall rvm and use rbenv to manage ruby versions.

Add the following to ~/.bashrc
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
rt PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"

source ~/.bashrc

Say 'Yes' to the prompt.

which bundle showed no output. Run: gem install bundle

References:
https://gorails.com/forum/rbenv-bundle-command-not-found
https://gorails.com/setup/osx/10.10-yosemite

Monday, April 20, 2015

Textmate 2 Setup Mate

You may get No such file or directory error when you create the symlink. 

1. Run:
ln -s /Applications/TextMate.app/Contents/SharedSupport/Support/bin/mate /usr/local/bin/mate
2. Go to Textmate -> Preferences, click on Terminal tab, click install for 'Shell support'.

Now the mate command will work.

Tuesday, April 14, 2015

short prompt in ubuntu 14.04 terminal

In your ~/.bash_profile add:

PROMPT_COMMAND='PS1="[\W]\\$ "'

Open a new terminal and you should see a small prompt.

Saturday, April 11, 2015

Using Custom Fonts in Rails 4.2

1. For Rails 4.2, copy the custom fonts to the folder app/assets/fonts. I am using the purchased fonts OpenSans.

2. Declare your font in your css file like this:

@font-face {
    font-family: 'OpenSans-Bold';
    src:url('OpenSans-Bold.ttf');
}

3. Use the declared font in css. For example:

font-family: 'OpenSans-Regular'

4. Add gem 'font-awesome-sass' to Gemfile

5. Run bundle intall

6. In application.scss, add:

@import "font-awesome-sprockets";
@import "font-awesome";