rspec – Tea-Driven Development https://blog.mattwynne.net Matt Wynne taking it one tea at a time Wed, 21 Aug 2019 13:05:19 +0000 en-US hourly 1 https://wordpress.org/?v=6.2 165828820 Fixing my testing workflow https://blog.mattwynne.net/2011/05/27/fixing-my-testing-workflow/ https://blog.mattwynne.net/2011/05/27/fixing-my-testing-workflow/#comments Fri, 27 May 2011 17:21:25 +0000 http://blog.mattwynne.net/2011/05/27/fixing-my-testing-workflow/ Continue reading "Fixing my testing workflow"

]]>
Okay I’m bored of this. I need to talk about it.

I love to use Ruby, RSpec, Cucumber and Rails to do test-driven development, but my tools for running tests are just infuriatingly dumb. Here’s what I want:

  • When a test fails, it should be kept on a list until it has been seen to pass
  • When more than one test fails:
    • Show me the list, let me choose one
    • Focus on that one until it passes, or I ask to go ‘back up’ to the list
    • When it passes, go back up to the list and let me choose again
    • When the list is empty, I get a free biscuit
  • When a test case is run, a mapping should be stored to the source files that were covered as it ran so that:
    • When a file changes, I can use that mapping to guess which test cases to run. Fuck all this naming convention stuff, it’s full of holes.
    • At any time, I can pipe the git diff though the tool to figure out which test cases to run to cover the entire commit I’m about to make.

When I say test case, I personally mean:

  • An RSpec example
  • A Cucumber scenario

…but it should work for any other testing framework too.

I feel like having a tool like this that I trusted would make a huge difference to me. There are all these various scrappy little pieces of the puzzle around: guard plugins, autotest, cucover, cucumber’s rerun formatter. None of them seem to quite do it, for me. Am I missing something?

Or shall we make one?

]]>
https://blog.mattwynne.net/2011/05/27/fixing-my-testing-workflow/feed/ 8 291
Using Capybara with RSpec Outside Cucumber https://blog.mattwynne.net/2010/12/01/using-capybara-with-rspec-outside-cucumber/ https://blog.mattwynne.net/2010/12/01/using-capybara-with-rspec-outside-cucumber/#comments Tue, 30 Nov 2010 23:18:32 +0000 http://blog.mattwynne.net/2010/12/01/using-capybara-with-rspec-outside-cucumber/ Continue reading "Using Capybara with RSpec Outside Cucumber"

]]>
If you want to try using Capybara for browser automation on it’s own, here’s a simple script to get you started:

require 'rubygems'

require 'capybara'
require 'capybara/dsl'

Capybara.default_driver = :selenium
Capybara.app_host = "http://www.google.com"

require "rspec/expectations"
class Google
  include Capybara
  include RSpec::Matchers

  def search_for(text)
    visit "/"
    fill_in "q", :with => text
    click_button "Search"
  end

  def ensure_results_contain(expected_text)
    page.should have_content(expected_text)
  end
end

google = Google.new
google.search_for("Matt Wynne")
google.ensure_results_contain("Tea")

To make this work you’ll need to install the capybara and rspec Ruby gems:

gem install capybara rspec
]]>
https://blog.mattwynne.net/2010/12/01/using-capybara-with-rspec-outside-cucumber/feed/ 2 272
Behaviour-Driving Routes in Rails with RSpec https://blog.mattwynne.net/2008/08/08/behaviour-driving-routes-in-rails-with-rspec/ https://blog.mattwynne.net/2008/08/08/behaviour-driving-routes-in-rails-with-rspec/#respond Fri, 08 Aug 2008 16:46:10 +0000 http://blog.mattwynne.net/2008/08/08/behaviour-driving-routes-in-rails-with-rspec/ Continue reading "Behaviour-Driving Routes in Rails with RSpec"

]]>
One thing that isn’t documented very well for RSpec is how to test your routes.

I came across an old post on the rspec mailing list which described a great way to do this:

describe TasksController "routing" do

    it "should route POST request for /tasks to the 'create' action" do
        params_from(:post, "/tasks").should == {:controller =>; "tasks", :action =>; "create"}
    end

end

Very nice.

]]>
https://blog.mattwynne.net/2008/08/08/behaviour-driving-routes-in-rails-with-rspec/feed/ 0 72