tools

Ninja Rails Developer

Warning: this configuration was tested only on MacOS X.

To create default project in Rails we just need to run command:

rails new my_app

However it creates project without many useful gems. I found nice Gem-set and some configuration hacks in Michael Hartl’s tutorial.

Instead of standard test framework (TestUnit) he use RSpec (which is more popular among Rails developers). To generate project without standard test, run command:

rails new my_app --skip-test-unit

Then use his Gemfile (this link is kept up to date). Copy it a paste into my_app/Gemfile. I recommend to uncomment everything (to use all Gems from the file).

Once Gemfile is modified, you need to install gems:

bundle install

Then you can run RSpec test:

bundle exec rspec

You may need to point the tests’ directory:

bundle exec rspec rspec/

It would be nice to run them with just ‘rspec’ command. To do that we need to run following commands (if we used RVM to install Rails):

rvm get head && rvm reload

cd ~/projects/my_app

bundle install --without production --binstubs=./bundler_stubs

After those steps you should be able to run RSpec with:

rspec

You should get a warning, that to maintain this possibility you need to add following line to ~/.bash_profile if it exists, otherwise add it to ~/.bash_login:

source ~/.profile

Michael Hartl’s Gem file contains ‘guard’. It allows us to run RSpec test each time, when we change some file (after save).

To initialize guard (if all above steps are performed, otherwise you need to add ‘bundle exec ‘ at the beginning):

guard init

It creates Guardfile in main project directory, which specify when tests should be run (which files should be monitored). To run guard:

guard

The last improvement is use the test server Spork. It allows to run tests faster. Without Spork, RSpec needs to reload entire Rails environment before run the tests (in each run). Spork loads the environment once, and then maintains a pool of processes for running future tests. Unfortunately it works only on POSIX systems (which means: doesn’t work on Windows).

To setup spork run:

spork --bootstrap

Then change spec/spec_helper.rb file to something like that:

require 'rubygems'
require 'spork'

Spork.prefork do
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'

  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
  RSpec.configure do |config|
    config.mock_with :rspec
    config.fixture_path = "#{::Rails.root}/spec/fixtures"
    config.use_transactional_fixtures = true
    config.infer_base_class_for_anonymous_controllers = false
  end
end

Spork.each_run do
  # This code will be run each time you run your specs.
end

You also need to configure RSpec to automatically use Spork. To do that, modify .rspec file:

--color
--drb

To run Spork:

spork

You can test difference between running tests with and without spork.

time rspec

In my case it was 4.821s without Spork, and 0.784 with Spork.

The disadvantage of Spork is that after e.g. changes in database we need to restart it.

The screencast showing advanced setup by Michael Hartl is available for free here. If you use SublimeText (as I do), you can follow this screencast to adjust it for Rails development. After that you will be able even to run tests from SublimeText!


Tools I use everyday

I published a list of tools I use everyday. Maybe someone will find something what is useful for him, but never heard about.

I will try to keep it up to date and it will be always accessible through http://jj09.net/tools.

Not all tools are multi-platform. For now, the list is only for Windows. Maybe sometime in the future I will publish also “Mac Specific” tools.


Copy and paste without formatting

When you copy some piece of text e.g. from Web Browser to Word it preserves formatting. Which is sometimes (most of the time) unnecessary. I dealt with it (so far) with paste the text into notepad or url input in the browser and then copy again, and finally paste into destination. In case of Web Browser it was: CTRL+C (from source) -> CTRL+T (open new tab) -> CTRL+V (paste formatted text) -> CTRL+A (select entire text) -> CTRL+C (copy again, now it is not formatted) -> CTRL+W (close the tab) -> CTRL+V (paste not formatted text into destination).

I didn’t do that very often, so it wasn’t big issue for me. However recently I was working on some documentation and I was copying/pasting code from IDE into Word a lot. After n-th time I googled for ‘copy and paste without formatting’ and I found nice discussion on StackOverflow. One of recommended tools is PureText.

PureText

It allows to paste text from clipboard without formatting, by WIN+V. This shortcut can be changed in options.

My life is much easier right now. I am able to save around 5-10 seconds per each CTRL+C/WIN+V.


Windows 8.1 Preview and Visual Studio 2013 Preview

At the build conference (June 26-28, 2013) Microsoft announced Windows 8.1 Preview and Visual Studio 2013 Preview. I installed them on my Virtual Machine. Just in case, to protect my system from some unexpected features 🙂

In case of Windows 8.1 there are no big changes. Only some small, useful improvements. I like ‘search all’, which enables you to search within apps, settings and files in the same time. However I am still using Search Everything, because it’s faster and more effective. It’s also cool to have the Start button, which brings you to the metro desktop, but again – no big deal (I was ok with WIN button). You can find list of improvements/changes here and here.

The new Visual Studio is more interesting. The One ASP.NET idea is applied. When you create new project, there are only one template: ‘ASP.NET Web Application’. Then in second step, you can choose which types of applications you want to include into it.

Visual Studio 2013 One ASP.NETVisual Studio 2013 One ASP.NET templates

There is MVC 5 (Preview) in it, along with various scaffolding options. You can e.g. scaffold just edit action.

Great feature for web developers: you can open page in multiple web browsers and then refresh them all from Visual Studio (e.g. after change in code).

The editors experience is improved. You can have code map in the scroll bar. HTML editor is rewritten from scratch. Short list of my favorite features:

  • new code snippets (in HTML document try: ‘div.myClass*4>lorem’ and click TAB)
  • intellisense in web.config
  • ALT + UP/DOWN – move code line up or down
  • ALT + 1/2 – extends text selection to level up or down
  • ALT+SHIFT+W – allows to surround selected text with new tag
  • ALT+V – voice commands (which shows shortcuts), yes we can speak to Visual Studio!
  • JavaScript frameworks intellisense (e.g. AngularJS)

But the greatest news is: WebEssentials2013 are now Open Source on github. Everyone can contribute. The policy is to add experimental features to WebEssentials and then move the hottest to Visual Studio (once they are tested). To see all, new, hot features watch Mads Kristensen’s talk at build 2013.

Another cool thing is possibility to ‘sign in’ in the Visual Studio. Once you sign in using your Microsoft account, you can synchronize settings across your devices. Now, it is enough to customize you Visual Studio only once.

There is much more new features. You can find them here and here.


Customize Terminal in Mac

Mac (UNIX) users use to be working with Terminal a lot. There is a few tips, which can make your life easier. First of all, if you are working on Mac – install iTerm2 and use it instead of standard Terminal. It is just more powerful. There is many features not available in standard Terminal. I find very useful the possibilities to search with CMD+F and copy entire path with double click by mouse (when you double click in standard Terminal it copies only one word). Another cool thing is ‘split terminal’ view. You can have multiple panes in one window.
iTerm2 - multipane

Second improvement to work faster is creation some aliases for commonly use commands. E.g. ls, clear or la -ls. You might also want to customize command prompt. I don’t like the standard one with Machine and user name (I always know in which Machine I am, and which user I am using – in case of doubts I can use whoami). To do add aliases and change default command prompt you need to modify your ~/.bashrc file. There is my .bashrc:

alias dir='ls -lap'
alias l='ls'
alias p='pwd'
alias c='clear'
alias o='open'
alias tree="ls -R | grep \":$\" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e '\s/^/   /' -e 's/-/|/'"
export PS1="[\W]$ "

Here you can find a list of various options to customize your command prompt.

To load this settings automatically each time you run Terminal, you also need to add below command to ~/.profile file:

source ~/.bashrc

After above improvements my terminal looks like that:

iTerm2

Hint: when you are playing with your command prompt (or aliases), you can simple run command source ~/.bashrc from terminal to check the result of changes you made.

And of course I use black terminal with green font color.

We are Hackers