= Tutors David Chelimsky, Developer, Articulated Man, Inc. ("Here in the States ... we are in East Germany, right?") Aslak Hellesøy, CTO, BEKK Consulting Dan North, Principal Consultant, ThoughtWorks * "Behaviour-driven development came out of me trying to teach Aslak TDD" = Overview and Background == What is BDD? === What problem does it solve? "Writing software that matters" * Stuff that is valuable to the business, that someone cares about === Outside-in Managers don't speak "tech", they speak "what the app is going to do" We don't want the project to deliver the wrong thing, and get canned 6 months in === People/Roles Many Rails teams are very small: 2-4 people When delivering applications these roles are in play: * Project manager: Responsibilty for getting things done - facilitator * Analyst: Helps the business person articulate the problem they are trying to solve * Tester: Once the problem is understood, the tester captures details; what "done" looks like * Scope creep: Happens when customer and development team doesn't have a shared understanding of "done" * BDD puts the tester in the project much earlier than usual === Two audience/levels * The intent of the test should also be embedded in the test itself * Functionality can be described for two audiences: * Programmers * Stakeholders === Background ==== BDD is entirely derivative TDD, ATPD, DDD, Rebecca Wirs-Brock, NLP ===== Domain Driven Design * Everybody on the team use the same language (incl. stakeholders) * Leads to far less misunderstandings * How do you get there? * Hard to get people to talk the same language * Has to be close to business language Example: * In business we have an "Account", which maps directly to the object "Account" * When the business guy says it's overdrawn, we have a "overdrawn?" property === "Second-generation" agile methodology ==== Getting the words right ==== Focusing on outcomes * See so many projects with focus on fulfilling these and these requirements * Opinionated software BDD DEF: Writing software that matters == What is rspec? === Origins * David Stills learned about BDD and wanted a framework for it * Take the focus away from this "test" word * AgileDocs: Parses JUnit test code and spits out a text file * People started using sentences naming their test code * Leads to the rspec way: describe VehicleRegistration do it "should do stuff" do ... end end === Code-by-example === Story running == What is rspec not? = Anti-patterns = Hot topics = Introduce the tuturial == Writing a story Story * Title: Plan a Cup * Narrative * As a [role] * I want [feature] * So that [benefit] Acceptance criteria: Scenarios * Given [some context] * Given [some other context] * When [some event occurs] * Then [expect some outcome] * And [another outsome] == Ping Pong TDD * Pair programming and TDD combined * One developer writes the test * The other developer makes the test pass == rspec basics === user_spec module rspec translates "be_in_role" to "in_role?" === user Uses Ruby predicate: in_role? = ExampleRunner vs. StoryRunner * Story corresponds to Rails integration tests * A story needs to run in a World (a module), which is implemented as RailsStory for Rails = RSpec generators % ./script/generate rspec_scaffold (takes usual arguments, but also generates rspec stuff) = Autotest * It runs your tests continually in the background so you don't have to run them your self = Refactoring * Improve the design without changing the behavior