3. Unit Tests
Test-Driven Development
Behavior-Driven Development
Tuesday, April 27, 2010
4. 1. Unit test-ове
2. Test-Driven
3. Behavior-Driven
4. RSpec
5. Cucumber
Tuesday, April 27, 2010
5. 1. Unit test-ове
2. Test-Driven
3. Behavior-Driven
4. RSpec
5. Cucumber
Tuesday, April 27, 2010
6. class Programmer
def implement_a_change(project, change)
files = self.open_related_files(project, change)
while true
self.attempt_change(change, files)
project.run()
result = self.click_around_and_test(project)
project.stop()
break if result.successful?
end
self.commit_code(files)
self.hope_everything_went_ok()
end
end
Tuesday, April 27, 2010
82. assert_raise(InvalidRecord) do
user.save!
end
lambda { user.save! }.should raise_error(InvalidRecord)
Tuesday, April 27, 2010
83. assert_raise(InvalidRecord) do
user.save!
end
lambda { user.save! }.should raise_error(InvalidRecord)
assert_difference "User.count", 1 do
user.create!
end
Tuesday, April 27, 2010
84. assert_raise(InvalidRecord) do
user.save!
end
lambda { user.save! }.should raise_error(InvalidRecord)
assert_difference "User.count", 1 do
user.create!
end
lambda {
user.save!
}.should change { User.count }.by(1)
Tuesday, April 27, 2010
85. class Stack < Test::Unit::TestCase
def set_up()
@stack = Stack.new
end
def test_empty
assert @stack.empty?
@stack.push 42
assert !@stack.empty?
end
def test_pop
@stack.push 42
@stack.push 5
assert_equal 5, @stack.pop
assert_equal 42, @stack.pop
asser_raise(StackEmptyError) { @stack.pop }
end
end
Tuesday, April 27, 2010
86. describe Stack do
before(:each) do
@stack = Stack.new
end
it "should be able to tell whether it is empty" do
@stack.should be_empty
@stack.push 42
@stack.should_not be_empty?
end
it "should pop the items in reverse order" do
@stack.push 42
@stack.push 5
@stack.pop.should == 5
@stack.pop.should == 42
lambda { @stack.pop }.should raise_error(StackEmptyError)
end
end
Tuesday, April 27, 2010
87. describe Stack do
context "(empty stack)" do
it "should be empty"
it "#pop should raise an exception"
end
context "(non-empty stack)" do
it "should not be empty"
it "#pop should return the top element"
it "#pop should remove the top element"
end
end
Tuesday, April 27, 2010
89. 1. Unit test-ове
2. Test-Driven
3. Behavior-Driven
4. RSpec
5. Cucumber
Tuesday, April 27, 2010
90. Feature: Manage posts
In order to be able to spread wisdom
the blogger
wants to be able to write about anything he wants
Scenario: Writing a new post
Given that there are no posts
And I am logged in
When I go to the new post page
And I fill "Title" with "F1rst p0st"
And I fill "Content" with "This is my first post"
And I press "Publish"
Then I should be on the front page
And I should see "This is my first post"
And there should be a new post called "F1rst p0st"
Tuesday, April 27, 2010
91. Given /^I am logged in$/ do
end
When /^I go to (.*?)$/ do |page|
end
When /^I fill "([^"]*)" with "([^"]*)"$/ do |field, content|
end
When /^I press "([^"]*)"$/ do |button_name|
end
Then /^I should be on (.*?)$/ do |page|
end
Then /^I should see "([^"]*)"$/ do |text1|
end
Then /^there should be a new post called "([^"]*)"$/ do |name|
end
Tuesday, April 27, 2010