Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

App de ejemplo para taller Steak

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 app
Octocat-spinner-32 config
Octocat-spinner-32 db Remove sqlite3 databases from git May 12, 2010
Octocat-spinner-32 doc
Octocat-spinner-32 lib
Octocat-spinner-32 public
Octocat-spinner-32 script
Octocat-spinner-32 spec
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 README
Octocat-spinner-32 Rakefile
README
#########################
Steak / Capybara demo app
#########################

This is a simple app with some examples of Steak & Capybara testing.

To get it running, install the required gems:

  [sudo] gem install rspec rspec-rails steak capybara database_cleaner launchy

Then create your databases:

  rake db:create:all
  rake db:migrate

And watch the specs run:

  spec spec/acceptance


################
Some quick notes
################

1.- Prepare your app for Rspec and Steak.

Steak runs on top of Rspec, so to get all this running do this:

  # environments/test.rb
  config.gem "rspec", :lib => false, :version => ">= 1.2.0"
  config.gem "rspec-rails", :lib => false, :version => ">= 1.2.0"
	config.gem 'steak'
	config.gem 'capybara'

And then generate the needed files:

  script/generate rspec
  script/generate steak

2.- Create your acceptance suite.

  script/generate acceptance_spec article_management

3.- Execute your acceptance suite.

  # this will run all specs
	rake spec
	
	# this will run all specs on the acceptance directory
  spec spec/acceptance

	# and this will only run the specified spec
  spec/acceptance/article_management_spec.rb 


################################
Testing JavaScript with Selenium
################################

rack-test, Capybara's default driver, is the recommended option as it is the fastest. But it cannot run JavaScript.

On this example app, we've opted for Selenium, which is slow, but it's nice to see your browser controlled by ghosts. A popular, faster alternative is Culerity.

To change the Capybara driver, you can do it this way:

  Capybara.current_driver = :selenium

And then you can turn back to the default driver with:

  Capybara.use_default_driver

As we only want to use Selenium where JavaScript testing is needed, we've provided a way to activate it only on some scenarios. See spec/support/javascript.rb and look for the scenarios where we pass Rspec the :js => true option.

Another thing to keep in mind while using Selenium is that we need to deactivate transactional fixtures. This is done on spec_helper.rb:

  config.use_transactional_fixtures = false

When you do this, you also need to clean the database before each scenario is run. See spec/support/database_cleaning.rb for this. We're using the database_cleaner gem although you could just use ActiveRecord.


########################################
About features, contexts and backgrounds
########################################

For the article management test suite, we're defining a feature "Article management" divided on 4 contexts: "Browsing", "Creation", "Edition", "Deletion". This way we separate the scenarios into groups, but there's also a nice way to be able to define a common background for all the scenarios (at the feature level), while being able to define particular backgrounds at the context level, like this:

feature "My feature" do

  background do
    # This is the common background
  end
  
  context "Browsing" do
    background do
      # This background is only for the browsing context
  	end

    scenario ...
    scenario ...
  end

  context "Creation" do
    background do
      # This background is only for the creation context
  	end

    scenario ...
    scenario ...
  end

end


##################
About rails routes
##################

You can't access rails routes from inside Steak. That is, although you might define an :articles resource, you won't be able to use articles_path on your integration tests.

You need to define them on spec/support/paths.rb. That's a good practice indeed, as routes will become part of your acceptance suite.


###########################
Some links worth looking at
###########################

http://github.com/cavalle/steak
http://github.com/jnicklas/capybara
http://github.com/dchelimsky/rspec
http://www.slideshare.net/sergio.gil/acceptance-testing-with-steak-and-capybara
http://jeffkreeftmeijer.com/2010/steak-because-cucumber-is-for-vegetarians/
http://openmonkey.com/articles/2010/04/javascript-testing-with-cucumber-capybara
http://www.ferdev.com/2010/03/10/testing-ajaxupload-con-capybara-culerity/
http://en.wikipedia.org/wiki/Capybara


###############
:: Thank you ::
###############

This little example was put together by Jaime Iniesta with help from:

* Raúl Murciano http://twitter.com/happywebcoder
* Emili Parreño http://twitter.com/eparreno
* Luismi Cavallé http://twitter.com/cavalle

If you'd like to contribute, just fork me or send me a message through github or twitter

Thanks everybody!

Jaime Iniesta
jaimeiniesta@gmail.com
http://jaimeiniesta.com
http://github.com/jaimeiniesta
http://twitter.com/jaimeiniesta
Something went wrong with that request. Please try again.