Showing posts with label Ruby. Show all posts
Showing posts with label Ruby. Show all posts

Monday, May 25, 2009

What is Rack?

Rack is a specification or a standardized way in Ruby to interact with a web server. It specifies how to accept a request from a web server and how to respond to a web server. Even though it sounds very simple, it opens up lot of options.

Check out these links for more information,

Wednesday, April 16, 2008

Please teach me rspec

I was first introduced to BDD like 4 years back by Dave Astel's article. I really liked the idea. It totally made sense to me. I was like damn this is the way we have to think for designing objects. That time I was working in a java project. Igor and I were like okay lets do BDD and started naming our Junit test methods like testDogShouldBarkWhenThrownStoneAt . When jBehave released I wanted to use it, but I never got a chance.

When I started working on yewoh, I was so excited that now I can chose whatever framework I want. Being a BDD addict, I obviously chose rspec. It is a great framework for doing BDD.It gives you nice syntax to express behaviors in "when" and "should" format .It felt very natural for me to write verifications for verifying my object behavior instead of tests.

Now after using rspec for sometime, I have some questions about rspec.

  • What is the best way to organize specs? In rails project, specs are arranged in folders like models, controllers etc. I do not have a problem arranging the spec files, but I am not sure how to organize specs itself. Does anyone has some good practices that worked for them?
  • Sometimes my objects have behaviors like "Player When power is on It should start playing When play button is pressed " . In this behavior I have two When conditions. How do you express this behavior in rspec ? Should I have it like


describe Player, "When play button is pressed"
it "should start playing if power is on"
....
end
end

using a if condition. Or should I have something like this

 describe Player, "When power is on and play button is pressed"
it "should start playing"
...
end
end
  • In unit test, usually we write tests to make sure our method do not blow up when we pass nil for example. I feel it is a good test to have. How do we writes spec for this kind of situations?  
Rspec documentation has good explanations and examples for rspec syntax. But I am looking for best practices for using rspec.

It will be great if you all share your experience with rspec.

Monday, March 31, 2008

Hope and Change

Enterprises are comfortable to use Java or C# as there are corporate backings for these languages. But for ruby there are no corporations backing it up. In this case, I was not sure how successfully Ruby will become in enterprises. I do not think a big health care system will be implemented using Ruby in near future. I really wanted to see Ruby become more mainstream, so we can build applications that have more impact on people's life rather than just social network site. That is why I wrote my previous blog "Who is responsible for Ruby?" to get an idea of what others think.

After talking to some of my friends and thinking over this weekend, I feel Ruby will soon become mainstream. Enterprises will start using ruby. But I think this change will not come in a traditional way. This change won't happen because some big corporation started backing up ruby. I think this change will happen because of Ruby community. Eventually enterprises have to start using ruby because of its wonderful developer community otherwise they will be left out.

To sum it up,
"Ruby is a grassroots movement to change Enterprises"

Wednesday, March 26, 2008

Who is responsible for Ruby?

In Qcon London 2008 conference , I attended a panel discussion for what type of projects should we use rails. As one of the audience mentioned during the discussion, that all the panel members were pro-ruby :) It is not a big deal, but I just thought it was funny. I have lot of respect for all those panel members. 


The discussion for some reason was totally off topic. Probably the discussion about what types of project can be implemented using rails happened like 5% of time. Most of the discussion was about why nobody from ruby community was worried about ruby running so slow in Windows. Someone from audience mentioned if Ruby community wants ruby to become mainstream and accepted as a language by all enterprises, it should run faster in Windows. Panel members said that they do not really care that much about ruby getting accepted in Enterprises. They told that they are doing it because Ruby as a language makes easy for them to solve the problems.

I totally accept that. If I find a language that is helping me to solve a problem more eloquently, than I will use that language. I do not care whether that language will be accepted by all big enterprises or not. If there is someone smart in those enterprises, than s/he will decide what language is good for solving their particular problem.

But one question enterprises will be asking, "who is responsible for RUBY ?" so that they can blame them when something goes wrong.

Sunday, March 23, 2008

Ruby is more object oriented than Java!

This simple example proves that Ruby is more object oriented than java.

To find absolute of a number,

in Java we need to use a separate class - Math.abs(-24)

but,

in Ruby abs functionality is built in the number - -24.abs