Rspec - RSpec is testing tool for the Ruby programming language. It is designed to make Test-Driven Development a productive and enjoyable experience.
More @ http://rspec.info/
Guard - Guard is a command line tool to easily handle events on file system modifications. So you don't have to run the test each and every time when you change the files. Guard keeps you focus on the tests and text editor or IDE.
More @ https://github.com/guard/guard/blob/master/README.md
$git clone git://github.com/mohanraj-nagasamy/rspec-test.git
$cd rspec-test
$ls -l
lib - is where your source goes.
spec - is where your tests goes (RSpec files)
Now install the rspec gem if you haven't installed yet. Try rspec -v to test it.
$gem install rspec
Now install the guard gem if you haven't installed yet. Try guard -v to test it.
$gem install guard
$guard -i -n f -c
It will watch for the file changes and runs the test for you. You don't have to run the tests every time when you change the files (including tests and the file you are testing).
$subl . #Sublime in my case
Stay focus on the editor and keep writing tests.
Remember:
lib - is where your source goes.
spec - is where your tests goes (RSpec files).
And the movie memento - TDD is kind of that exp.
Some people want to do it by manually on their own. So here are the steps.
But you may have to modify the following files or copy from - https://github.com/mohanraj-nagasamy/rspec-test.git
.rspec
Guardfile
$mkdir rspec-test/{lib,spec}
$cd rspec-test
The folder structure will look like-
$rspec-test
-lib
-spec
lib - is where your source goes.
spec - is where your tests goes (RSpec files)
now install the rspec gem if you haven't installed yet. Try rspec -v to test it.
$gem install rspec
$rspec --init #It will create .rspec file and spec_helper.rb.
Copy fine tuned from - https://github.com/mohanraj-nagasamy/rspec-test.git
Let's say you want to test User spec. Create user_spec.rb inside spec dir
$subl spec/user_spec.rb #open file
#spec/user_spec.rb
require 'user'
describe User do
it "should be equal" do
user = User.new
user.name = "test-1"
user.name.should be == "test-1"
end
end
create user.rb inside lib dir
$subl lib/user.rb
#lib/user.rb
class User
attr_accessor :name
end
$rspec spec/user_spec.rb -f d -c
You should be able to see the test running successfully.
Install the guard gem if you haven't installed yet. Try guard -v to test it.
$gem install guard
$guard init # This is will create Guardfile.
You may not need all the contents so copy Guardfile from - https://github.com/mohanraj-nagasamy/rspec-test.git
$guard -i -n f -c
It will watch for the file changes and runs the test for you. You don't have to run the tests every time when you change the files (including tests and the file you are testing).
$subl . #Sublime in my case
Stay focus on the editor and keep writing tests.
Remember:
lib - is where your source goes.
spec - is where your tests goes (RSpec files).
And the movie memento - TDD is kind of that exp.
http://stackoverflow.com/questions/201385/getting-started-with-rspec-looking-for-tutorials
https://www.relishapp.com/rspec/rspec-expectations/v/2-0/docs/matchers/include-matcher