Logo

Peeler for cucumber on windows

about 3 years ago | Gourav Tiwari: easy_software = Agile.find(ruby_on_rails)

Cucumber is one of the cornerstone for BDD in Ruby on Rails. Non technical or business participants can write tests (called as features or stories) in plain English and cucumber allows the developers to execute these tests.

I was very excited when I started looking at it. In my test.feature file, I have a feature:

Feature: Grant and revoke access
To have proper security model
User should have proper access

Scenario: Revoke access of a user who do not deserves access
Given Gourav is a user who do not deserves access
When system run cron job to verify access
Then Gourav's access should be revoked

There are two ways to execute this file:

1. Cucumber as a plugin (by rake task):
It starts eating 'a' and 'A' characters on windows:

Feture: Grnt nd revoke ccess # fetures/grnt_nd_revoke_ccess.feture

To hve proper security model

User should hve proper ccess

Scenrio: Revoke ccess of user who do not deserves ccess # fetures/test.feture:5

Given Gourv is user who do not deserves ccess # fetures/test.feture:6

When system run cron job to verify ccess # fetures/test.feture:9

Then Gourv's ccess should be revoked # fetures/test.feture:10


I went to open source community and worked little bit on issue #81 (first encounter with Opensource community :) ) and found troubleshooting for this issue. Now "rake features" works well and give proper output.


2. Cucumber as a
gem:


cucumber features\test.feature It gives:

Feature: Grant and revoke access # features/test.feature

To have proper security model

User should have proper access

Scenario: Revoke access of a user who do not deserves accessC:/ruby/lib/ruby/gems/1.8/
gems/cucumber-0.1.12/bin/../lib/cucumber/tree/scenario.rb:70:in length': undefined methodjlength' for Scenario ng (NoMethodError)

from C:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.1.12/bin/../lib/cucumber/tree/scenario.rb:74:in `max_line_length'


from C:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.1.12/bin/../lib/cucumber/tree/scenario.rb:78:in `padding_length'

from C:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.1.12/bin/../lib/cucumber/formatters/pretty_formatter.rb:197:in `p
adding_spaces'

from C:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.1.12/bin/../lib/cucumber/formatters/pretty_formatter.rb:58:in `sc
enario_executing'

from C:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.1.12/bin/../lib/cucumber/broadcaster.rb:15:in `__send__'

from C:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.1.12/bin/../lib/cucumber/broadcaster.rb:15:in `method_missing'

from C:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.1.12/bin/../lib/cucumber/broadcaster.rb:13:in `each'

from C:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.1.12/bin/../lib/cucumber/broadcaster.rb:13:in `method_missing'

... 12 levels...

from C:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.1.12/bin/../lib/cucumber/cli.rb:11:in `execute'

from C:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.1.12/bin/cucumber:6

from C:/ruby/bin/cucumber:19:in `load'

from C:/ruby/bin/cucumber:19



I found a workaround for this:

In file C:\ruby\lib\ruby\gems\1.8\gems\cucumber-0.1.12\lib\cucumber\tree\Scenario.rb on line number 69, I have changed jlength to length:

@length ||= Cucumber.language['scenario'].length + 2 + (@name.nil? ? 0 : @name.length)

Similarly, in file C:\ruby\lib\ruby\gems\1.8\gems\cucumber-0.1.12\lib\cucumber\tree\step.rb on line number 22 I have changed jlength to length:
keyword.length + 1 + name.length


But for a better solution I am still working on issue #81

How I use TDD for Integration and Isolation testing

about 3 years ago | Alex Rothenberg: Common Sense Software

I read an interesting post today by David Chelimsky who wrote RSpec A case against a case against mocking and stubbing. Its about mocking in testing and isolated vs integrated tests. I liked it all but what I particularly liked is how it describes the process of outside-in development.

To quote:


  1. Write scenarios in plain text with cucumber (driven by user stories, organized in features).

  2. Write the code for a step (or part of a step), run the feature, and observe the failure.

  3. Optionally (yes, it depends – and why is the topic for another blog) drive out a view with a view spec. When I say “drive out,” I mean a very granular Red/Green/Refactor cycle that only involves this view, and only enough of this view to support satisfaction of the failing step in the cucumber feature.

  4. Drive out a controller action using the same, granular Red/Green/Refactor cycle. And it may not be the entire controller action I think I want, covering all the cases I think I want. Just enough to support satisfaction of the failing step.

  5. Drive out the parts of the model that I need to satisfy the failing step, using the same granular R/G/R process.

  6. Run the cucumber feature and assess where I am.



In my projects I think I'm pretty good at following 3,4 &5 but I've struggled with steps 1 & 6. With the advent of cucumber I think now is the time to work on those other steps. I'll let you know how it goes in the New Year.

How I use TDD for Integration and Isolation testing

about 3 years ago | Alex Rothenberg: Common Sense Software

I read an interesting post today by David Chelimsky who wrote RSpec A case against a case against mocking and stubbing. Its about mocking in testing and isolated vs integrated tests. I liked it all but what I particularly liked is how it describes the process of outside-in development.

To quote:


  1. Write scenarios in plain text with cucumber (driven by user stories, organized in features).

  2. Write the code for a step (or part of a step), run the feature, and observe the failure.

  3. Optionally (yes, it depends – and why is the topic for another blog) drive out a view with a view spec. When I say “drive out,” I mean a very granular Red/Green/Refactor cycle that only involves this view, and only enough of this view to support satisfaction of the failing step in the cucumber feature.

  4. Drive out a controller action using the same, granular Red/Green/Refactor cycle. And it may not be the entire controller action I think I want, covering all the cases I think I want. Just enough to support satisfaction of the failing step.

  5. Drive out the parts of the model that I need to satisfy the failing step, using the same granular R/G/R process.

  6. Run the cucumber feature and assess where I am.



In my projects I think I'm pretty good at following 3,4 &5 but I've struggled with steps 1 & 6. With the advent of cucumber I think now is the time to work on those other steps. I'll let you know how it goes in the New Year.

Khuda...

about 3 years ago | Sukhpal Bhatti: life

Je dukhaan wich hi tainu yaad karde haante har saa wich ik hauka de,de gyan te lai lai paavein jaanay khuda mainu vi sewa da ik mauka de...

Bug/patch with rspec-rails and helper instance variables

about 3 years ago | Alex Rothenberg: Common Sense Software

I finally got around to upgrading my version of rspec-rails from one that's almost a year old and came across an issue with the way implicit module inclusion is handled.

If you have a handler that uses memoization to cache some information in instance variables such as this (I'm not sure if this is a smell but my project has some examples of it)


module UsersHelper
def all_users
@users ||= User.find(:all)
end
end



You would expect this spec to work


describe UsersHelper do
it "should find all users" do
User.expects(:find).with(:all).returns(result=mock)
helper.all_users.should == result
end
end



Sometimes it does but if any other spec has called helper.all_users previously it will fail as the memoized @users variable is not nil so the collection is reused.

I have submitted a lighthouse patch to rspec-rails that fixes the problem so hopefully they will agree to fix it soon. Until then patch is available on github in my fork or rspec-rails if you want to use it.

Knows which specs are slowing down my spec suite

about 3 years ago | Alex Rothenberg: Common Sense Software

I often watch my specs run with the ........'s marching across my terminal and sometimes it seems to pause as it hits a particularly slow one. I figure there's some poorly written spec that's slowing my entire suite down and I should figure out what it is and fix it. But I rarely (if ever) take the time to track down the offender so never fix it. I just discovered that the clever folks writing rspec have taken away my excuse for laziness. I can tell it to report on the slowest specs by putting a line in my spec.opts file telling it to use the ProfileFormatter (see the first line below)


--format profile
--colour
--loadby mtime
--reverse



For example running the specs on my current project I get this output.


Profiling enabled.
........(a bunch more dots)

Top 10 slowest examples:
2.4908950 WikiContent should find all activity for a user
0.8061750 WikiContent should find recent activity for a user in last 15 days
0.2438460 WikiContent::Version should allow limit on results from finding recent activity
0.1821710 User should have a list of owned content
0.1700670 WikiContent should find results if access type is not same as role of the user but role of user is 'Leader'
0.1593900 ContentsController allows PUT request to 'update' action for 'member' role
0.1514150 Search::SearchResponse gets the wiki content id of an asset from the xml response
0.1470310 Content should always allow leaders to see all pages
0.1394920 Page should delete all comments when destroyed
0.1370330 ContentsController should save content and create the uploaded asset on successful POST to the 'create' action



Over the next few days I will find time to take a look at 'WikiContent find all activity' and 'WikiContent find recent activity' specs as they are the two clear outliers.

I now have no excuse to not optimize my slowest specs because I didn't know which they were!

Bug/patch with rspec-rails and helper instance variables

about 3 years ago | Alex Rothenberg: Common Sense Software

I finally got around to upgrading my version of rspec-rails from one that's almost a year old and came across an issue with the way implicit module inclusion is handled.

If you have a handler that uses memoization to cache some information in instance variables such as this (I'm not sure if this is a smell but my project has some examples of it)


module UsersHelper
def all_users
@users ||= User.find(:all)
end
end



You would expect this spec to work


describe UsersHelper do
it "should find all users" do
User.expects(:find).with(:all).returns(result=mock)
helper.all_users.should == result
end
end



Sometimes it does but if any other spec has called helper.all_users previously it will fail as the memoized @users variable is not nil so the collection is reused.

I have submitted a lighthouse patch to rspec-rails that fixes the problem so hopefully they will agree to fix it soon. Until then patch is available on github in my fork or rspec-rails if you want to use it.

Knows which specs are slowing down my spec suite

about 3 years ago | Alex Rothenberg: Common Sense Software

I often watch my specs run with the ........'s marching across my terminal and sometimes it seems to pause as it hits a particularly slow one. I figure there's some poorly written spec that's slowing my entire suite down and I should figure out what it is and fix it. But I rarely (if ever) take the time to track down the offender so never fix it. I just discovered that the clever folks writing rspec have taken away my excuse for laziness. I can tell it to report on the slowest specs by putting a line in my spec.opts file telling it to use the ProfileFormatter (see the first line below)


--format profile
--colour
--loadby mtime
--reverse



For example running the specs on my current project I get this output.


Profiling enabled.
........(a bunch more dots)

Top 10 slowest examples:
2.4908950 WikiContent should find all activity for a user
0.8061750 WikiContent should find recent activity for a user in last 15 days
0.2438460 WikiContent::Version should allow limit on results from finding recent activity
0.1821710 User should have a list of owned content
0.1700670 WikiContent should find results if access type is not same as role of the user but role of user is 'Leader'
0.1593900 ContentsController allows PUT request to 'update' action for 'member' role
0.1514150 Search::SearchResponse gets the wiki content id of an asset from the xml response
0.1470310 Content should always allow leaders to see all pages
0.1394920 Page should delete all comments when destroyed
0.1370330 ContentsController should save content and create the uploaded asset on successful POST to the 'create' action



Over the next few days I will find time to take a look at 'WikiContent find all activity' and 'WikiContent find recent activity' specs as they are the two clear outliers.

I now have no excuse to not optimize my slowest specs because I didn't know which they were!

FUNNY HOW IT HAPPENS

about 3 years ago | Sukhpal Bhatti: life

Funny how it happens... you get up one morningand see...that life is not completefunny h ow it happensand you see......that the one who hurt you mostwas yourselffunny how it happenswhen you realize that the one thingthat you always wanted to go away...forever...will stay forever to remind youand that still you need it...funny how it happenedthat it took you to lose itto realize what you hadfunny

Its a Gloomy day

about 3 years ago | Surbhi Bhati: Clean Desk, Jammed drawers

Well, there is so much happening to me at the moment, not that I am overwhelmed by it, in fact I am someone who likes to be immersed in her going arounds. You know, the busier it is, the happier I am, because then my stupid mind does not bring unnecessary thoughts to me. Anyway, currently I feel down, shattered, angry and frustrated like many of my Indian fellows not just because what happened in the last few days, but more because we still don’t see the much needed reform being brought in, we still don’t see the long-long slept conscience of our worthless politicians arising. Anyway, enough has already been and still being said. I only hope God gives them enough sense to implement theat. Please God, it will do even if it’s momentary, but LET THEE BE SENSIBLE.

Now this was from the nations side, but there is also a change happening from the personal front. I feel little scared of myself sometimes, because never ever in my life have I thought of what will happen to me in future, but this time I am, and this is scaring me, because its stupid to be worried about the future. It scares you, because you cant think that everything will be wonderful, because everything cant be wonderful, as life would have been perfect, and its not. So you will think about the bad things happening and that is bound to make you feel bad. So basically you will be sad about something that hasn’t happened at all!! So its very bad thinking about the future, its better to let things happen naturally, keep your head down, do your work, and leave the rest to God. Yesss..this is what I have got to do. Good that I got to it finally by writing here.

Humm..think that’s enough for today. Work Calling!!