The document discusses the history and concepts of test-driven development (TDD) and behavior-driven development (BDD). It traces the origins of TDD from the 1970s and mentions how BDD grew out of TDD in the 2000s. It provides examples of test code written using the RSpec framework in Ruby to specify and test behaviors using a domain-specific language for writing tests.
102. class EmptyMovieList < Spec::Context
def setup
@list = MovieList.new
end
def should_have_size_of_0
@list.size.should_equal 0
end
def should_not_include_star_wars
@list.should_not_include quot;Star Warsquot;
end
end
class OneMovieList < Spec::Context
def setup
...
def should_have_size_of_1
...
end
147. calc_spec.rb:
context quot;1+1 quot; do
setup do
@sum = 1 + 1
end
specify quot; 2 quot; do
@sum.should_eql 2
end
expectation
end
context quot; quot; do
specify quot;2-0 0 quot; do
(2 - 0).should_eql 0
end
end
163. context ¡°5 ¡± do
setup do
@five_dollar = Money.doller(5)
end
specify ¡°2 10 ¡± do
(@five_doller * 2).should_eql Money.doller(10)
end
specify ¡°5 ¡± do
@five_doller.should_not_eql 5
end
...
end
...