test driven ruby
TRANSCRIPT
Ruby is...● programming language● dynamic ● open source ● focus on simplicity and productivity ● it has an elegant syntax that is natural to read and easy to write
● appeared in 1995.
● Became popular in 2005. with the apperance of Ruby on Rails (web application framework written in Ruby)
test driven development - tdd
add a test
run all tests and see if the new one fails
write some code
run tests
refactor code
-repeat-
fail
pass
software development methodology:
the TDD circle of life
TEST FAILS
TEST PASSES:“IT’S ALL GREEN”
refactor
refactor
refactor
refactor
refactor
RSpec
TDD framework / test tool for Ruby.
Domain specific language.
Aims to resemble specifications in natural language.
TIME FOR RSPEC SETUP
1. Add RSpec gem (package) to your project
2. Write ‘specs’ (tests / specifications) 3. Run them with rspec
4. Observe the reports of the specs crashing.
5. Proceed with the TDD cycle.
String breakfast = null;
if (breakfast == null) {
breakfast = "burek";
}
breakfast = nil
if breakfast == nil
breakfast = "burek"
end
String breakfast = null;
if (breakfast == null) {
breakfast = "burek";
}
if breakfast.nil?
breakfast = "burek"
end
String breakfast = null;
if (breakfast == null) {
breakfast = "burek";
}
if !breakfast
breakfast = "burek"
end
String breakfast = null;
if (breakfast == null) {
breakfast = "burek";
}
unless breakfast # unless = if not
breakfast = "burek"
end
String breakfast = null;
if (breakfast == null) {
breakfast = "burek";
}
breakfast = "burek" unless breakfast
public void greetSomeone(String name) {
return "Hello there, " + name;
}
def greet_someone(name)
"Hello there, " + name
end
public void greetSomeone(String name) {
return "Hello there, " + name;
}
def greet_someone(name)
"Hello there, #{name}"
end
String[] people = {"Bob", "Billy", "Jim"};
int i = 0;
while(i < people.length) {
System.out.println(people[i]);
i++;
}
people = ["Bob", "Billy", "Jim"]
i = 0
while i < people.size
puts people[i]
i += 1
end
String[] people = {"Bob", "Billy", "Jim"};
for(int i = 0; i < people.length; i++) {
System.out.println(people[i]);
}
people = ["Bob", "Billy", "Jim"]
for i in 0..people.size
puts people[i]
end
String[] people = {"Bob", "Billy", "Jim"};
for(String person: people) {
System.out.println(person);
}
people = ["Bob", "Billy", "Jim"]
people.each { |person| puts person }