15. ИДЕЯ
# bowling_spec.rb
require 'bowling'
describe Bowling, "#score" do
it "returns 0 for all gutter game" do
bowling = Bowling.new
20.times { bowling.hit(0) }
bowling.score.should == 0
end
end
16. ИДЕЯ
# bowling_spec.rb
NO!
require 'bowling'
describe Bowling, "#score" do
it "returns 0 for all gutter game" do
bowling = Bowling.new
20.times { bowling.hit(0) }
bowling.score.should == 0
end
end
18. КОММУНИКАЦИИ
Хочу кастомный
Porsche
# bowling_spec.rb
require 'bowling'
describe Bowling, "#score" do
it "returns 0 for all gutter game" do
bowling = Bowling.new
20.times { bowling.hit(0) }
bowling.score.should == 0
end
end
разработка
написание спек
идея
19.
20. ФУНКЦИОНАЛ
Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
Scenario: Add two numbers
Given I have entered 10 into the calculator
And I have entered 5 into the calculator
When I press ‘plus’
Then the result should be 15
21. ФУНКЦИОНАЛ
Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
Scenario: Add two numbers
Given I have entered 10 into the calculator
And I have entered 5 into the calculator
When I press ‘plus’
Then the result should be 15
22. СЦЕНАРИИ
Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
Scenario: Add two numbers
Given I have entered 10 into the calculator
And I have entered 5 into the calculator
When I press ‘plus’
Then the result should be 15
23. ШАГИ
Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
Scenario: Add two numbers
Given I have entered 10 into the calculator
And I have entered 5 into the calculator
When I press ‘plus’
Then the result should be 15
25. ОПРЕДЕЛЕНИЯ
require 'calculator'
Given /I have entered (d+) into the calculator/ do
|n|
@calc.push n.to_i
end
When /I press (w+)/ do |op|
@result = @calc.send op
end
Then /the resoulr should be (.*)/ do |result|
@result.should == result.to_f
end
26. ОПРЕДЕЛЕНИЯ
require 'calculator'
Given /I have entered (d+) into the calculator/ do
|n|
ПИШУТСЯ на
Ruby
@calc.push n.to_i
end
When /I press (w+)/ do |op|
@result = @calc.send op
end
Then /the resoulr should be (.*)/ do |result|
@result.should == result.to_f
end
27. МИНУСЫ
1. Не все PHP-разработчики знают/хотят знать Ruby
2. Сложность при описании входных условий
3. Невозможность использования PHP библиотек
4. Скорость работы кросс-языкового решения
28.
29. 1. Написан с нуля на PHP5.3
2. Написан с применением Symfony Components
3. Старается быть Cucumber’ом с входными/выходными данными
4. Полностью нативное решение на PHP
5. Столь же быстр, что и Cucumber (проверено)
6. Поддерживает полную и17ю
7. Полностью расширяем и настраиваем
8. Поддерживает различные типы лоадеров
30. ФУНКЦИОНАЛ
Feature: Serve coffee
In order to earn money
Customers should be able to
buy coffee at all times
Scenario: Buy last coffee
Given there are 1 coffees left in the machine
And I have deposited 1$
When I press the coffee button
Then I should be served a coffee
35. ИСПОЛНЕНИЕ
Feature: Behat Console Runner
Scenario: Run feature from CLI
Given I have default Behat configuration
When I call ‘behat -f progress’
Then it should pass
<?php
$steps->Then(‘/^it should (fail|pass)$/’,
function($world, $status) {
...
}
);
36. ИСПОЛНЕНИЕ
Feature: Behat Console Runner
Scenario: Run feature from CLI
Given I have default Behat configuration
When I call ‘behat -f progress’
Then it should pass
<?php
$steps->Then(‘/^it should (fail|pass)$/’,
function($world, $status) {
// $status == ‘pass’
}
);
37. СТАТУСЫ
<?php
$steps->Then(‘/^it should pass$/’, function($world) {
return true;
});
$steps->Then(‘/^it passes$/’, function($world) {
return false;
});
$steps->Then(‘/^it should fail$/’, function($world) {
throw new Exception();
});
$steps->Then(‘/^it should pend$/’, function($world) {
throw new EverzetBehatExceptionPending();
});
38. СТАТУСЫ
<?php
$steps->Then(‘/^it should pass$/’, function($world) {
...
});
$steps->Then(‘/^it should pass$/’, function($world) {
// Will throw exception on definitions read
});
$steps->Then(‘/^it’s good$/’, function($world) {
...
});
$steps->Then(‘/^it’s w+$/’, function($world) {
// Will throw exception on ‘it should pass call’
});
41. HOW MUCH IS THE FISH?
<?php # ./user.php
class User
{
public function __construct($username, $age = 1)
{
}
public function getName() {}
public function getAge() {}
}
42. FEATURE
# ./features/user.feature
# language: ru
Функционал: Базовый Пользователь
Чтобы работать с пользователями
Как разработчик сайта
Я хочу иметь доступ к
пользовательской модели
Сценарий: Создание пользователя
Допустим у нас нет пользователей
Если мы добавим пользователя ‘everzet’
То у нас должно быть 1 пользователей
И имя у первого пользователя ‘everzet’
46. РЕАЛИЗАЦИЯ
<?php # ./user.php
class User
{
protected $name, $age;
public function __construct($username, $age = 1)
{
$this->name = $username;
$this->age = $age;
}
public function getName() { return $this->name; }
public function getAge() { return $this->age; }
}