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

Property Based Testing on Rails

Property Based Testing on Rails

The Ruby community is known by its strong culture of testing, but this is not an excuse to refuse alternative approaches. One of these are Property Testing. In those tools we do not express examples, but the possible input formats; instead of specific outputs, characteristics that must remain true. In this way our tools are capable of exhaustively generate test cases and look for failures. In this talk we'll see how to create lean suites with wide coverage using Clojure's power to test a Rails application.

Video [pt-br]: https://www.youtube.com/watch?v=WKuZWzi2oRQ

Andrew Rosa

March 07, 2015
Tweet

More Decks by Andrew Rosa

Other Decks in Programming

Transcript

  1. it "sorts a list" do v = [3, 1, 2]

    s = sort(v) expect(s).to eq([1, 2, 3]) end
  2. it "sorts a list" do v = [3, 1, 2]

    s = sort(v) expect(s).to eq([1, 2, 3]) end
  3. it "sorts a list" do v = [3, 1, 2]

    s = sort(v) expect(s).to eq([1, 2, 3]) end
  4. it "sorts a list" do v = [3, 1, 2]

    s = sort(v) expect(s).to eq([1, 2, 3]) end
  5. it "sorts a list" do v = [3, 1, 2]

    s = sort(v) expect(s).to eq([1, 2, 3]) end
  6. #sorts ascending sorts an empty list sorts a list with

    single item sorts a list with multiple items ! Finished in 0.00179 seconds 3 examples, 0 failures
  7. ∀ v → vector int each pair a, b in

    sort(v) a <= b v → [] v → [-1] v → [2 -1 1 -1 -2 5] v → [4] v → [7 9 -4 -4] …
  8. [23 -17 8 -20 -35 -25 -22 10 11 -19

    9 -3 -42 -33 -34 -11 7 -28 -5 38 39 -26 -29 42 0 -41 33 -35 19]
  9. !

  10. !

  11. [23 -17 8 -20 -35 -25 -22 10 11 -19

    9 -3 -42 -33 -34 -11 7 -28 -5 38 39 -26 -29 42 0 -41 33 -35 19]
  12. 01 def sort(v) 02 if v.include?(42) 03 v 04 else

    05 v.sort 06 end 07 end v1 v2 v3 v4 …
  13. (defmulti dispatch! :action) ! (defmethod dispatch! :add-entry [action] (to base-url)

    (input-text “#entry_value" (str (:value action))) (submit "#entry_value"))