Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker
Mike Gehard

Packaging Cucumber step definitions for reuse

Mike Gehard
Monday, September 20, 2010

So I’ve been doing a bunch of BDD development these days using Cucumber as a starting point.

While working with client, the question came up about how they could share step definitions across multiple teams of developers.

I then remembered that the Aruba gem is just that, a collection of Cucumber step definitions.

So if you are looking for a way to start packaging up those step definitions that you have used on multiple projects and are tired of copying across projects, check out how the Aruba gem does it and go from there.

Thanks to the Cucumber and Aruba folks for sharing some very useful technology that allows us all to raise the bar when it comes to delivering quality software.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Mike Gehard

Testing Rails3 Generators using Cucumber and Aruba

Mike Gehard
Wednesday, September 15, 2010

In an effort to continue my contributions to the open source Ruby/Rails ecosystem, I decided to help the factory_girl_rails team move the Rails3 generators from the rails3-generators project into the factory_girl_rails project.

Like all good Ruby/Rails developers, they asked to make sure that I had tests written around the generators. I thought for a bit on how I was going to do this and then I wandered across the Cucumber feature files in the rspec-rails repo and found my answer.

Rspec-rails (and RSpec2 as well) uses a gem called Aruba to easily write Cucumber features around things that happen from the command line.

If you’d like to check out the result of using Cucumber and Aruba to test Rails3 generators, head over to my fork of the factory_girl_rails gem and check out the features/generators.feature file.

Hopefully the changes will be merged into the official factory_girl_rails repo soon and the generators will live closer to home.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Mike Gehard

Testing Rails generators with Cucumber…

Mike Gehard
Tuesday, August 24, 2010

I didn’t realize that Cucumber was so versatile…

http://gravityblast.com/2009/08/11/testing-rails-generators-with-cucumber/

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Mike Gehard

Cucumber and Sunspot…

Mike Gehard
Tuesday, August 24, 2010

In continuing with my Cucumber themed posts, here is a great post about using Cucumber and Sunspot together…

http://opensoul.org/2010/4/7/cucumber-and-sunspot

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Mike Gehard

Capybara/Cucumber and waiting for Javascripty stuff to happen

Mike Gehard
Friday, August 20, 2010

A little ditty that makes it really easy to wait for something Javascripty to happen…like a Javascript dialog to appear that gets populated from an AJAX call.

The has_css? method call will wait until the element shows up and if it doesn’t show up before the Capybara timeout expires then it will return false.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Mike Gehard

Testing Resque with Cucumber

Mike Gehard
Wednesday, August 18, 2010

For some reason the Universe keeps sending great Cucumber related stories to me via Twitter.

Here is another great one from the folks at Square on how to test Resque based functionality via Cucumber:

http://corner.squareup.com/2010/08/cucumber-and-resque.html

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Mike Gehard

Rocket powered Cucumber features in Rails3

Mike Gehard
Saturday, August 14, 2010

Are your Cucumber features that use the @javascript tag slowing you down?

Try adding the following to your Gemfile:

gem 'thin', :group => :test

and see what happens.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Abhijit Hiremagalur

Standup 08/04/2010: Accounting on Rails anybody?

Abhijit Hiremagalur
Wednesday, August 4, 2010

Ask for Help

  • Double-entry/ledger based accounting in Rails (i.e. Quickbooks in Rails for free)

Ideally would be tied in with user/role system where each accounting entry would be tied to a user, but also reconciled against a master account.

Recommendations? Latest and greatest?

One suggestion was to look at the code that Wesabe open sourced code when they closed their doors.

  • Error message when opening Rubymine “Invalid Git Root”

This is likely because the project included a submodule that wasn’t configured correctly, fix this in under Rubymine’s version control preferences.

Add submodule screen in Rubymine

Interesting Things

  • Test 404 handling (e.g. rescue_from ActiveRecord::RecordNotFound, :with => :render_record_not_found) with Cucumber by temporarily setting ActionController::Base.allow_rescue = true. This is usually set to false in features/support/env.rb
  • JSON.pretty_generate hates Rails 3 Hashes

 

  • Use window.postMessage to communicate between IFrames in a standard way

This should work in most modern browsers. Follow the Mozilla docs, NOT the various blog posts about this.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Standup 9/11/2009: to_param now required in functional tests

Pivotal Labs
Friday, September 11, 2009

Ask for Help

“Do you have to use to_param in functional tests?”

In the past you could simply provide an object in a param list in functional tests and the to_param for the object would be called to get the proper value for the parameter. This is now broken, forcing you to use object.to_param every time.

Perhaps not helpful for existing projects but I recommend you use cucumber, webrat, or even selenium rather than Rails functional tests. Rails functional tests require that you specify parameters and specify them correctly. If you get them wrong your functional tests might continue to pass for the wrong reason. Here’s another “bad params in functional tests” post.

Interesting Things

  • Rubyconf program should be available today on their website
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Run JavaScript in Selenium tests. Easily.

Pivotal Labs
Thursday, March 5, 2009

Here’s the gist of this post: gist.github.com/58876

Ever since I’ve started using Webrat, a lot of the pain of Selenium has gone away
for me. There’s still a little bit of pain though. Part of it is caused by the fact
that it’s harder than it should be to just execute arbitrary bits of JavaScript in
in your current window under test. Well no more. Here’s a helper:

module SeleniumHelpers
  # Execute JavaScript in the context of your Selenium window
  def run_javascript(javascript)
    driver.get_eval <<-JS
      (function() {
        with(this) {
          #{javascript}
        }
      }).call(selenium.browserbot.getCurrentWindow());
    JS
  end

  private

  # If running in regular Selenium context, get_eval is defined on self.
  def driver
    respond_to?(:selenium) ? send(:selenium) : self
  end
end

To use it with Cucumber, do like so:

World do |world|
  world.extend(SeleniumHelpers)
  world
end

To use it with POS, do like so:

class JavaScriptHelperTest < SeleniumTestCase
  include SeleniumHelpers

  # your tests go here...
end

Now what?

Now to run JavaScript in your Selenium window, just call run_javascript. Note
that it’s always going to return a String, so you may have to massage the output
a tad:

checked_boxes_count = run_javascript <<-JS
  jQuery('input[type=checkbox]:checked').size();
JS

checked_boxes_count         # => "3"
checked_boxes_count.to_i   # => 3

Cooler stuff

While Webrat’s DSL for traversing web apps is awesome, I’ve always found the
alternatives (Polonium for example) to not jive well with how I think. They’re
way better than talking directly to Selenium, you’re still locked in to a certain
style. The run_javascript helper makes it easier to write your own helpers that
fit your own style.

module ElementHelpers
  class Element
    def initialize(context, selector)
      @context, @selector = context, selector
    end

    def hide!
      call(:hide)
    end

    def show!
      call(:show)
    end

    def visible?
      call(:is, ':visible') == 'true'
    end

    private

    def call(fn, *args)
      @context.run_javascript <<-JS
        return jQuery(#{@selector.inspect})[#{fn.to_s.inspect}](#{args.map(&:inspect).join(', ')});
      JS
    end
  end

  def locate(selector)
    Element.new(self, selector)
  end
end

Now you can write your tests like so:

class JavaScriptHelperTest < ActiveSupport::TestCase
  include SeleniumHelpers
  include ElementHelpers

  def setup
    @element = locate('#all')
  end

  def test_visible_by_default
    assert @element.visible?
  end

  def test_hide_element
    @element.hide!
    assert ! @element.visible?
  end

  def test_show_element
    @element.hide! # setup
    @element.show!
    assert @element.visible?
  end
end

Credit should go to Brian Takita, since he did most of the hard work and I just wrote a method. Let me
know if you have any issues or ideas with the helper, and may all your tests be green.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Topics

  • agile (778)
  • rails (113)
  • testing (86)
  • ruby (83)
  • ruby on rails (70)
  • jobs (62)
  • javascript (54)
  • techtalk (44)
  • rspec (38)
  • activerecord (29)
  • productivity (29)
  • gogaruco (29)
  • ironblogger (29)
  • git (28)
  • nyc (27)
  • rubymine (25)
  • mobile (22)
  • bloggerdome (20)
  • cucumber (20)
  • process (19)
  • pivotal tracker (19)
  • jasmine (19)
  • design (18)
  • ios (18)
  • webos (17)
  • objective-c (17)
  • android (16)
  • palm (16)
  • "soft" ware (16)
  • fun (15)
  • tracker ecosystem (15)
  • ci (15)
  • cedar (15)
  • rails3 (14)
  • performance (14)
  • bdd (14)
  • gem (13)
  • selenium (12)
  • css (12)
  • goruco (12)
  • bundler (12)
  • tdd (12)
  • meetup (11)
  • railsconf (11)
  • nyc-standup (11)
  • capybara (10)
  • mac (10)
  • mojo (10)
  • chef (10)
  • rubygems (9)
Subscribe to cucumber Feed
  1. ←
  2. 1
  3. 2
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >