Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Fix - Simple, stupid testing framework for Ruby

Fix - Simple, stupid testing framework for Ruby

A talk at Paris.rb @ Le Wagon about the new Fix specing framework, as an alternative to RSpec.

More details: http://www.meetup.com/fr-FR/parisrb/events/220872045/

Video: https://youtu.be/XV6tVZtKMfA

Cyril Kato

March 01, 2016
Tweet

More Decks by Cyril Kato

Other Decks in Programming

Transcript

  1. Testing with RSpec, the result was processed over... rspec 3.4.0

    rspec-core 3.4.3 rspec-expectations 3.4.0 63 LOC 7 389 LOC 3 917 LOC + +
  2. Testing with RSpec, the result was processed over... rspec 3.4.0

    rspec-core 3.4.3 rspec-expectations 3.4.0 rspec-mocks 3.4.1 63 LOC 7 389 LOC 3 917 LOC 4 106 LOC + + +
  3. Testing with RSpec, the result was processed over... rspec 3.4.0

    rspec-core 3.4.3 rspec-expectations 3.4.0 rspec-mocks 3.4.1 rspec-support 3.4.1 63 LOC 7 389 LOC 3 917 LOC 4 106 LOC 1 624 LOC + + + +
  4. Testing with RSpec, the result was processed over... rspec 3.4.0

    rspec-core 3.4.3 rspec-expectations 3.4.0 rspec-mocks 3.4.1 rspec-support 3.4.1 diff-lcs 1.2.5 63 LOC 7 389 LOC 3 917 LOC 4 106 LOC 1 624 LOC 1 405 LOC + + + + +
  5. Testing with RSpec, the result was processed over... rspec 3.4.0

    rspec-core 3.4.3 rspec-expectations 3.4.0 rspec-mocks 3.4.1 rspec-support 3.4.1 diff-lcs 1.2.5 63 LOC 7 389 LOC 3 917 LOC 4 106 LOC 1 624 LOC 1 405 LOC + + + + + 18 504 LOC!!
  6. BTW

  7. require 'rspec' RSpec.describe(-42) do describe '#abs' do it { expect(described_class.abs).to

    equal 42 } end end I don’t care about class or instance methods
  8. require 'fix' Fix.describe(-42) do on :abs do it { MUST

    equal 42 } end end The front object
  9. require 'fix' Fix.describe(-42) do on :abs do it { MUST

    equal 42 } end end An absolute requirement
  10. The key words "MUST", "MUST NOT", "SHOULD", "SHOULD NOT", and

    "MAY" in this document are to be interpreted as described in RFC 2119.
  11. require 'rspec' greeting = 'Hello world!' RSpec.describe greeting do context

    'Alice' do before { greeting.gsub!('world', 'Alice') } it { expect(greeting).to eql 'Hello Alice!' } end context 'Bob' do before { greeting.gsub!('world', 'Bob') } it { expect(greeting).to eql 'Hello Bob!' } end end
  12. require 'rspec' greeting = 'Hello world!' RSpec.describe greeting do context

    'Alice' do before { greeting.gsub!('world', 'Alice') } it { expect(greeting).to eql 'Hello Alice!' } end context 'Bob' do before { greeting.gsub!('world', 'Bob') } it { expect(greeting).to eql 'Hello Bob!' } end end No isolation of the code to avoid the side effects
  13. ➜ rspec 2-example/greeting_spec.rb .F Failures: 1) Hello world! Bob should

    eql "Hello Bob!" Failure/Error: it { expect(greeting).to eql 'Hello Bob!' } expected: "Hello Bob!" got: "Hello Alice!" Finished in 0.01521 seconds 2 examples, 1 failure
  14. require 'fix' greeting = 'Hello world!' Fix.describe greeting do context

    'Alice' do on :gsub!, 'world', 'Alice' do it { MUST eql 'Hello Alice!' } end end context 'Bob' do on :gsub!, 'world', 'Bob' do it { MUST eql 'Hello Bob!' } end end end
  15. ➜ ruby 2-example/greeting_fix.rb .. Ran 2 tests in 0.005775 seconds

    100% compliant - 0 infos, 0 failures, 0 errors
  16. app = 'OMGLOL' def app.equal?(*) true end require 'rspec' RSpec.describe

    app do it { expect(app).to be 42 } end rspec 3-example/strange_app_spec.rb . Finished in 0.00097 seconds 1 example, 0 failures
  17. app = 'OMGLOL' def app.equal?(*) true end require 'rspec' RSpec.describe

    app do it { expect(app).to be 42 } end rspec 3-example/strange_app_spec.rb . Finished in 0.00097 seconds 1 example, 0 failures
  18. app = 'OMGLOL' def app.equal?(*) true end require 'rspec' RSpec.describe

    app do it { expect(app).to be 42 } end rspec 3-example/strange_app_spec.rb . Finished in 0.00097 seconds 1 example, 0 failures Let’s fix that!
  19. app = 'OMGLOL' def app.equal?(*) true end require 'r_spec' RSpec.describe

    app do it { expect(app).to be 42 } end rspec 3-example/strange_app_spec.rb F 1. Failure: Expected "OMGLOL" to be 42. /Users/cyril/parisrb/3-example/strange_ app_spec.rb:10:in `block (2 levels) in <top (required)>' Ran 1 tests in 0.000195 seconds 0% compliant - 0 infos, 1 failures, 0 errors