Skip to content

Repository files navigation

CodeDrivenDevelopment

Ever see a test and think, "wow, this test cares a lot about the exact abstract syntax tree of the code?" CDD aims to generate tests like that. Here's some example input:

classBunker < ActiveRecord::Basevalidate:password,secure: truevalidate:location,:protected=>truedefalert_staffstaph.all_alertStaff.alert_allenddefalert_presidentSecretService.stand_downalert_staff || go_crazyendend

And this is what CDD thinks of it:

describeBunkerdoit{shouldvalidate_secure_of:password}it{shouldvalidate_protected_of:location}describe"#alert_staff"dolet(:obj){described_class.new}let(:all_alert){double(:all_alert)}let(:staph){double(:staph)}let(:alert_all){double(:alert_all)}subject{obj.alert_staff}beforedoallow(staph).toreceive(:all_alert).and_return(all_alert)allow(obj).toreceive(:staph).and_return(staph)allow(Staff).toreceive(:alert_all).and_return(alert_all)endit"calls staph.all_alert"dosubjectexpect(staph).tohave_received:all_alertexpect(obj).tohave_received:staphendit"calls Staff.alert_all"dosubjectexpect(Staff).tohave_received:alert_allendenddescribe"#alert_president"dolet(:obj){described_class.new}let(:stand_down){double(:stand_down)}subject{obj.alert_president}beforedoallow(SecretService).toreceive(:stand_down).and_return(stand_down)endit"calls SecretService.stand_down"dosubjectexpect(SecretService).tohave_received:stand_downenddescribe"#alert_staff is truthy"dobeforedoallow(obj).toreceive(:alert_staff).and_return('alert_staff')allow(obj).toreceive(:go_crazy)endit"returns #alert_staff"doexpect(subject).toeq'alert_staff'endit"doesn't call #go_crazy"dosubjectexpect(obj).not_tohave_received:go_crazyendenddescribe"#alert_staff is falsey"dobeforedoallow(obj).toreceive(:alert_staff).and_return(false)allow(obj).toreceive(:go_crazy).and_return('go_crazy')endit"returns #go_crazy"doexpect(subject).toeq'go_crazy'endit"calls #alert_staff"dosubjectexpect(obj).tohave_received:alert_staffendendendend

Installation

Add this line to your application's Gemfile:

gem 'code_driven_development'

And then execute:

$ bundle

Or install it yourself as:

$ gem install code_driven_development

Usage

$ cdd path/to/some/source.rb

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

Automatically generate tests from your Ruby code!

Resources

Stars

11 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages