Tuesday, October 15, 2013

BDD and Acceptance Testing with Rspec and Capybara

BDD helps us to figure out
1)What to test. - Use cases or User Stories. Test what something does(behavior) rather than what something is (structure)
2)Where to start. - From the outermost layer.
3)What to ignore.- Ignore the stuff in the middle.

-Notes
 -Proper acceptance test treat your application as a black box. Which means that they should have no knowledge of your application.
 - Capybara is a browser automation library.
- helps you test web applications by stimulating how  areal user would interact with your app.
 - It is agnostic about the driver running your tests and comes with Rack::Test and Selenium support built in.
- Rack::Test run requests against your app, then provides the resulting HRML to capybara and rspec examination.

-When testing
 Remember order for the db commands:

rake db:reset
rake db:migrate
rake db:test:prepare
rake db:populate

Sunday, October 13, 2013

Running PostgreSQL with rails.

1. Run the PostgreSQL by issuing the following command:

$ sudo /etc/init.d/postgresql start

Expected Output:
 * Starting PostgreSQL 9.1 database server

2. Run your Rails Server using the command:

$ rails server

3. To run your database:  psql -U user_name db_name

4. Enjoy.

Notes: When PostgreSQL is configured it creates a configuration file pg_hba.conf. 

Issues faced:

There was a peer authentication error while running the rails server
Solution:
Change the configuration in the PostgreSQL conf file.

i.e. pg_hba.conf
Issue the following command.

$ sudo nano /etc/postgresql/9.1/main/pg_hba.conf

Update the


local all postgres peer
to
local all postgres md5

That would solve the problem with authentication.  

Saturday, October 12, 2013

What is the difference between locally installed and system wide installation of gems.

The locally installed gems ~/.gem are accessible only by the user. Whereas the system wide installation of gem, which is in /usr/lib/ruby can be accessed by everyone.

Installing nokogiri gem for Ruby on Rails project

1. Install
$ sudo apt-get install libxslt-dev libxml2-dev

2.$ sudo gem install nokogiri


Probably you would be able to install nokogiri with the above two steps.

Friday, October 11, 2013

Login Loop after changes to file for including hibernation

If you are trying to login to your system and getting into a loop cycle, then the reason could be the .Xauthority file.

Check the file by issuing the following command:

Alt + Ctrl + F1

Login with your credentials.

$ ls -lah

The .Xauthority file should belong to the user you are trying to login with.

If it is not, probably this is the issue.

Solve it by assigning it to the user you want to login with.

Issue the following command:

$ chown username:username .Xauthority

The above command should solve the issue.


How to install ImageMagick

1. Simply go to the website:

ImageMagick

2. echo Hurray!

Testing in Ruby On Rails

RSpec: Framework to provide testing in Ruby on Rails projects.

Capybara: Provides behavioral testing with Ruby on Rails.

FactoryGirl: Provides data for testing using tools like Capybara.