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.

How to kill a process in Ubuntu

1.Type Top and check all the processes running

2. If you dont' get your process name there.

Then if you know what process you kill.

Use:

(here I want to check any processes with 'jet)

ps -aef | grep mine

You would get something like this:

sony@ubuntu:~$ ps -aef | grep mine
sony      3682     1  0 13:50 ?        00:00:00 /bin/sh /home/sony/Downloads/RubyMine-5.4.3.2.1/bin/rubymine.sh
sony      3747  3682  4 13:50 ?        00:00:10 /usr/lib/jvm/jdk1.7.0_40/bin/java -Xms128m -Xmx512m -XX:MaxPermSize=250m -XX:ReservedCodeCacheSize=64m -XX:+UseCodeCacheFlushing -ea -Dsun.io.useCanonCaches=false -Djava.net.preferIPv4Stack=true -Djb.vmOptionsFile=/home/sony/Downloads/RubyMine-5.4.3.2.1/bin/rubymine64.vmoptions -Xbootclasspath/a:/home/sony/Downloads/RubyMine-5.4.3.2.1/bin/../lib/boot.jar -Didea.paths.selector=RubyMine50 -Didea.platform.prefix=Ruby -Didea.no.jre.check=true -Djb.restart.code=88 com.intellij.idea.Main
sony      3900  2426  0 13:53 pts/1    00:00:00 grep --color=auto mine

I want to kill 3682.
'Simply kill 3682

Installing VIM editor on Ubuntu

1. $sudo apt-get install vim
2. Navigation when in VIM editor

Hit escape before executing any of the below:

  • :q to quit
  • :q! to quit without saving
  • :wq to write and quit
  • :qa to quit all
The bashrc file is located in the home folder.

Once the environment variable are set.

Source the .bashrc file and check whether environment variables are set or not.

(How to source : Go to your application folder and enter

source ~/.bashrc
The above sources your .bashrc file.)

For instance if you have set LDAP_HOST.

Then enter
   $echo $LDAP_HOST
The above command should return the value you applied to it.
e.g.  it would give. (in .bashrc you have, export LDAP_HOST=anyhost)
anyhost


Installing PostGresql

1. Use the sudo command

$ sudo apt-get install postgresql

2. Basic Server Settings

$ sudo -u postgres psql postgres

postgres=# \password postgres


--Enter password.(twice)


Type Cntrl D to exit postgres prompt.



3. $ sudo apt-get install postgresql-contrib

4. Installing postgresql-contrib

$ sudo apt-get install postgresql-contrib

5. If $ psql -l
     throws the error:
     psql: FATAL:  role "user_name" does not exist

It means you have to create a new user and assign it superuser access.

$ sudo -u postgres createuser user_name


Then you are asked if you want to make this as the superuser. Choose as required.

6. $ psql -l

Gives
 List of databases
        Name        |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges  
--------------------+----------+----------+-------------+-------------+-----------------------



 ......some text........
 
 
 7. check
psql --version 
And you should get something like this: 
psql (PostgreSQL) 9.1.9
contains support for command-line editing
 
Enjoy! 
 
8. If the user wants to check all PostGresSQL clusters. Enter command:
$ pg_lsclusters

You get something like this:

Version Cluster   Port Status Owner    Data directory                     Log file
9.1     main      5432 down   postgres /var/lib/postgresql/9.1/main       /var/log/postgresql/postgresql-9.1-main.log

 
 
 

Installing JetBrains

1. Download the file from http://www.jetbrains.com/ruby/download/

2. Unpack the contents using

tar xfz RubyMine-5.4.3.tar.gz

3. Go to the folder/bin.

Run

     ./rubymine.sh


4. Enjoy

Installing Ruby via RVM

1. $ rvm install ruby-1.9.2-p180
2. Add this to ~/.bashrc file
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

3. $ source ~/.rvm/scripts/rvm
4. $ type rvm | head -n 1
       should return a
       rvm is a function
5. $ rvm --default use ruby-1.9.2-p180

Thursday, October 10, 2013

Installing Ruby Version Manager on Ubuntu

1. Installing curl.

sudo apt-get install curl

2. Installing build-essentials

sudo apt-get install build-essential

3. Installing development libraries:

sudo apt-get install zlib1g-dev libreadline-dev libssl-dev libxml2-dev

4. Finally install RVM

$ bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)


5. And that's it.

Check the version:

rvm -v


You will get something like this:

rvm 1.23.4 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]




Installing Oracle JDK in Ubuntu

1. Installing Java.

Things you need to know.

a) JDK - Java Development Kit. (Usually contains one ore more JRE with it)
    JRE - Java Runtime Environment.

b) x86 is for a 32-bit OS, and x64 is for a 64-bit OS

1.1 Download the JDK from http://www.oracle.com/technetwork/java/javase/downloads/index.html.

1.2 Uncompress the file.

Command:

tar -xvf jdk-7u40-linux-x64.tar.gz

The above command installs the JDK in the current path.

1.3 Next task is to put the JDK in usr/lib path.

For this create a dir in /usr/lib/jvm

$ sudo mkdir -p /usr/lib/jvm

Change the directory of the current install

$ sudo mv ./jdk1.7.0_40 /usr/lib/jvm/jdk1.7.0_40


1.4 Run the following commands:
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_40/bin/java" 1
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_40/bin/javac" 1

The above commands set the priority for the current install as 1.


1.5 Alter the ownership and permissions of the executables by running the following commands.
$ sudo chmod a+x /usr/bin/java
$ sudo chmod a+x /usr/bin/javac 
$ sudo chmod a+x /usr/bin/javaws
$ sudo chown -R root:root /usr/lib/jvm/jdk1.7.0_40

Now check the java version
$java -version


You must get something like this:

sony@ubuntu:~/Downloads$ java -version
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)

For more instructions checkout --
http://www.oracle.com/technetwork/java/javase/