Skip to content
high abstraction dsl for tests (from end user perspective) [kameleon - mean chameleon, from polish]
Ruby
Find file
Pull request Compare This branch is 155 commits behind miksturait:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
examples/spree
lib
spec
.gitignore
.rspec
.rvmrc
.travis.yml
CHANGELOG.textile
Gemfile
Gemfile.lock
Guardfile
LICENCE
README.textile
ROADMAP.textile
kameleon.gemspec

README.textile

Kameleon [chameleon]

Kameleon is a high abstraction dsl for better* writting acceptance, integration and functional tests using Capybara.
And “better” means: from the end user perspective.

Setup:

Kameleon requires:

  • rspec
  • capybara
  • devise ( kameleon uses paths suplied by devise. So if you’re using some other authentication solution, you might want to overwrite it )
  • selenium && racktest drivers
  • thin (if you want run your specs faster – add gem ‘thin’ to Gemfile in your app)

Before you start using kameleon ensure that capybara is properly loaded (in your test helper file)

require 'capybara/rails'

After that

gem install kameleon

will get you going.

Usage:

You start with kameleon by defining your user. Think of a name that describes the best the perspective from which you want to test something in your project. For the example below, we’ll choose “administrator”:

class TestUserAdministrator < Kameleon::User::Base
  def initialize(rspec_world, options={})
    @user = Factory(:admin_user)
    super
  end
  # performs do ... end block, by default scope is :main selector - if defined
  def page_areas
    {
        :top => '.header',
        :left => '.column sidebar',
        :second_level_menu_items => [:xpath, '//ul[@class="level_two"]/li'],
        :main => '#content'
    }
  end
  private
  def user_login_path
    rspec_world.new_admin_session_path
  end
end

And here is an example of rspec scenario, where our user will shine:

background do
     @admin = TestUserAdministrator.new(self, {:session_name => 'my_account', :driver => :selenium)
    end
    scenario "opening list of news", :status => 'done' do
        @admin.will do
          click "homepage", "community", "news"
          see "new medicine developed last weekend"
        end
        @admin.within(:row => 'some cell text') do
          see 'see all values in row that contains that text'
        end
        @admin.within(:column => 'some header') do
          see 'see all values in that column'
        end
        @admin.see :ordered => 'Z', 'X', 'Y'
        @admin.click :and_confirm => "Cancel"
        @admin.click :and_dismiss => "Cancel"
    end

Another example:

  feature "Products", :driver => :selenium do
      background do
        @admin = TestUserAdministrator.new(self) do
          visit spree.admin_path
        end
      end
      context "listing products" do
        scenario "products sorting" do
          Factory(:product, :name => 'apache baseball cap', :available_on => '2011-01-06 18:21:13:', :count_on_hand => '0')
          Factory(:product, :name => 'zomg shirt', :available_on => '2125-01-06 18:21:13', :count_on_hand => '5')
          @admin.click "Products"
          @admin.see :ordered => ["apache baseball cap", "zomg shirt" ]
          @admin.click "admin_products_listing_name_title"
          @admin.see :ordered =>  ["zomg shirt", "apache baseball cap"  ]
        end
      end

Tips & Tricks:

Session pooling

Kameleon has useful technique of session pooling implemented, that can speed up test suite greatly.
In order to enable it, you need to pass this to the RSpec.configure block, in spec_helper.rb:

config.after(:each) do
  ::SessionPool.release_all
end

Credits:

Something went wrong with that request. Please try again.