Behavior-driven development

BDD is about implementing an application by describing its behaviour from the perspective of its stakeholders.

  • User stories
  • Domain-Driven Development
  • Extreme Programming
    • Test-Driven Development
    • Acceptance Driven Test Planning
    • Continuous Integration

Bdd cycle

  1. Start with an Acceptance Test scenatio.
  2. Run the Acceptance Test scenatio.
  3. Red/Green/Refactor wuth Unit Tests.
    • View
    • Controller
    • Model
  4. Run the Acceptance Test scenatio again.

Init enviropment

Create gemset

Install Rails

Create Application

Add gems

Gemfile

Init testing tools

Init RSpec

config/application.rb spec/spec_helper.rb spec/features/features_spec_helper.rb

Meet the Capybara

Capybara is acceptance test framework for web applications.

Capybara helps to test web applications by simulating how a real user would interact with an app.

Test your app with Capybara

Registration feature

specs/features/registration_spec.rb

Fix 'register_path' error

config/routes.rb

Fix uninitialized constant UsersController

app/controllers/users_controller.rb

Fix the action 'new' could not be found for UsersController

app/controllers/users_controller.rb

Fix missing template 'users/new'

app/views/users/new.html.erb created

View specs

spec/views/users/new_spec.rb app/views/users/new.html.erb config/routes.rb

More view specs

spec/views/users/new_spec.rb app/views/users/new.html.erb Run views Run features

Controller specs

spec/controllers/users_controller_spec.rb app/controllers/users_controller.rb

Model specs

spec/models/user_spec.rb app/models/user.rb

Fix the action 'create' could not be found error

spec/controllers/users_controller_spec.rb app/controllers/users_controller.rb

Fix undefined local variable or method 'root_url' error

config/routes.rb app/controllers/pages_controller.rb

app/views/pages/home.html.erb created

Fix expected to find text 'Sign out'

app/views/lououts/application.html.erb

Fix expected to find text 'You registered'

app/views/lououts/application.html.erb

Homework

You need to write a simple web book store. Please implement the following user stories.

/

#