· 1 min read
Request Specs und Capybara
Download:
Download(20.3 MB, 13:16) Alternativer Download für iPod & Apple TV(20.6 MB, 13:16)
Resourcen:
- rspec-rails
- Capybara
- Database Cleaner
- Episode 155: Beginning with Cucumber
- Episode 156: Webrat
- Episode 187: Testing Exceptions
Quellcode:
[bash] bundle rails g rspec:install rails g integration_test task rake spec:requests [/bash]
[ruby] # Gemfile group :development, :test do gem ‘rspec-rails’ gem ‘capybara’, :git => ‘git://github.com/jnicklas/capybara.git’ gem ‘launchy’ gem ‘database_cleaner’ end
# spec/requests/tasks_spec describe “Tasks” do describe “GET /tasks” do it “displays tasks” do Task.create!(:name => “paint fence”) visit tasks_path page.should have_content(“paint fence”) end it “supports js”, :js => true do visit tasks_path click_link “test js” page.should have_content(“js works”) end end describe “POST /tasks” do it “creates task” do visit tasks_path fill_in “New Task”, :with => “mow lawn” click_button “Add” page.should have_content(“Successfully added task.”) page.should have_content(“mow lawn”) end end end
# spec_helper.rb require ‘capybara/rspec’
RSpec.configure do |config| # … config.use_transactional_fixtures = false config.before(:suite) do DatabaseCleaner.strategy = :truncation end
config.before(:each) do DatabaseCleaner.start end
config.after(:each) do DatabaseCleaner.clean end end [/ruby]
[html] <%= link_to_function “test js”, ’$(this).html(“js works”)’ %> [/html]