Skip to content

Instantly share code, notes, and snippets.

<% form_for @house_search do |form| %>
<div>
<%= form.label :keyword %>
<%= form.text_field :keyword %>
</div>
<div>
<%= form.label :price %>
<%= form.select :price, [['20-30', '20-30k']] %>
</div>
<div>
class HouseSearchTest < ActiveSupport::TestCase
should "produce only houses with the keyword in the description when sent #results for such a search" do
matching_house = Factory(:house, :description => 'foo')
nonmatching_house = Factory(:house, :description => 'bar')
results = HouseSearch.new('keyword' => 'fo').results
assert_all(results) {|house| house.description =~ /fo/}
end
should "produce only houses within the price range when sent #results for such a search" do
matching_house = Factory(:house, :price => 10)
class HouseSearchTest < ActiveSupport::TestCase
should "build a new HouseSearch with the expected params" do
params = {'keyword' => 'some keyword',
'price' => '20-30'}
house_search = HouseSearch.new(params)
params.each do |field, value|
assert_equal value, house_search.send(field)
end
end
class HouseSearchesTest < ActionController::TestCase
should_route :get, '/house_searches',
:controller => :house_searches,
:action => :index
context "GET to index with houses" do
setup do
@houses = [Factory.stub(:house), Factory.stub(:house)]
@search = HouseSearch.new
HouseSearch.stubs(:new).returns(@search)
class SlideshowsController < ApplicationController
before_filter :authenticate, :authorize
def show
if file_exists?(file)
render :file => file
else
render :nothing => true, :status => 404 and return false
end
end
slidedown tdd.md --template=import > tdd.html
!SLIDE
## why automated tests?
![Quizzical puppy](/images/quizzical_puppy.png)
!SLIDE
* prevent regressions
* prove functionality with executable code
sudo gem install nakajima-slidedown
vim tdd.md
#bee_button a {background-position: 0 0;}
#bee_button a:hover {background-position: 0 -41px;}
#bee button a:active {background-position: 0 -82px;}
#bee_button a {
display: block;
text-indent: -5000px;
width: 136px;
height: 41px;
background-image: url(/images/bee_button.png);
background-repeat: no-repeat;
}