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

jasmine-given is for givers

Justin Searls
November 16, 2011

jasmine-given is for givers

jasmine-given is a port of rspec-given, but for Jasmine. Details here: https://github.com/searls/jasmine-given

Basically, the extension lets you use a Given/When/Then DSL instead of trying to approximate Given/When/Then by using Jasmine's own beforeEach() & it(). Check out the slides and give it a try! You can play with the sample code inside your browser at http://is.gd/givensandwich

---
Need a web or mobile app built? Interested in training? Contact me at http://test-double.com and let's get in touch!

Justin Searls

November 16, 2011
Tweet

More Decks by Justin Searls

Other Decks in Programming

Transcript

  1. In the beginning was xUnit public void somethingSomething() { SandwichMaker

    subject = new SandwichMaker(); Sandwich sandwich = subject.make(); assertEquals(sandwich.getBread(),SOME_BREAD); }
  2. In the beginning was xUnit public void somethingSomething() { SandwichMaker

    subject = new SandwichMaker(); Sandwich sandwich = subject.make(); assertEquals(sandwich.getBread(),SOME_BREAD); } Arrange
  3. In the beginning was xUnit public void somethingSomething() { SandwichMaker

    subject = new SandwichMaker(); Sandwich sandwich = subject.make(); assertEquals(sandwich.getBread(),SOME_BREAD); } Arrange Act
  4. In the beginning was xUnit public void somethingSomething() { SandwichMaker

    subject = new SandwichMaker(); Sandwich sandwich = subject.make(); assertEquals(sandwich.getBread(),SOME_BREAD); } Arrange Act Assert
  5. then along came should public void itShouldHaveBread() { SandwichMaker subject

    = new SandwichMaker(); Sandwich sandwich = subject.make(); assertThat(sandwich).hasBread(); }
  6. then along came should public void itShouldHaveBread() { SandwichMaker subject

    = new SandwichMaker(); Sandwich sandwich = subject.make(); assertThat(sandwich).hasBread(); } public void itShouldHaveCheese() { SandwichMaker subject = new SandwichMaker(); Sandwich sandwich = subject.make(); assertThat(sandwich).hasCheese(); }
  7. RSpec gave us DRY specs that retained readability describe MakesSandwiches

    describe “#make” it “has bread” do subject = MakesSandwiches.new sandwich = subject.make() sandwich.should have_bread end end end
  8. RSpec gave us DRY specs that retained readability describe MakesSandwiches

    describe “#make” it “has bread” do subject = MakesSandwiches.new sandwich = subject.make() sandwich.should have_bread end it “has cheese” do subject = MakesSandwiches.new sandwich = subject.make() sandwich.should have_cheese end ... end end
  9. RSpec gave us DRY specs that retained readability describe MakesSandwiches

    describe “#make” it “has bread” do subject = MakesSandwiches.new sandwich = subject.make() sandwich.should have_bread end it “has cheese” do subject = MakesSandwiches.new sandwich = subject.make() sandwich.should have_cheese end ... end end
  10. RSpec gave us DRY specs that retained readability describe MakesSandwiches

    let(:subject) { MakesSandwiches.new } describe “#make” before(:each) { @sandwich = subject.make() } it “has bread” do @sandwich.should have_bread end it “has cheese” do @sandwich.should have_cheese end ... end end
  11. RSpec gave us DRY specs that retained readability describe MakesSandwiches

    let(:subject) { MakesSandwiches.new } describe “#make” before(:each) { @sandwich = subject.make() } it “has bread” do @sandwich.should have_bread end it “has cheese” do @sandwich.should have_cheese end ... end end Given
  12. RSpec gave us DRY specs that retained readability describe MakesSandwiches

    let(:subject) { MakesSandwiches.new } describe “#make” before(:each) { @sandwich = subject.make() } it “has bread” do @sandwich.should have_bread end it “has cheese” do @sandwich.should have_cheese end ... end end Given When
  13. RSpec gave us DRY specs that retained readability describe MakesSandwiches

    let(:subject) { MakesSandwiches.new } describe “#make” before(:each) { @sandwich = subject.make() } it “has bread” do @sandwich.should have_bread end it “has cheese” do @sandwich.should have_cheese end ... end end Given When Then
  14. RSpec gave us DRY specs that retained readability describe MakesSandwiches

    let(:subject) { MakesSandwiches.new } describe “#make” before(:each) { @sandwich = subject.make() } it “has bread” do @sandwich.should have_bread end it “has cheese” do @sandwich.should have_cheese end ... end end Given When Then Then
  15. and rspec-given made an honest DSL of it. describe MakesSandwiches

    Given(:subject) { MakesSandwiches.new } describe “#make” When(:sandwich) { subject.make() } Then { sandwich.should have_bread } Then { sandwich.should have_cheese } end end
  16. so then I just ported that same thing to jasmine.

    describe "MakesSandwiches", -> Given -> @subject = new MakesSandwiches describe "#make", -> When -> @sandwich = @subject.make() Then -> expect(@sandwich).toHave("bread") Then -> expect(@sandwich).toHave("cheese")
  17. so then I just ported that same thing to jasmine.

    describe "MakesSandwiches", -> Given -> @subject = new MakesSandwiches describe "#make", -> When -> @sandwich = @subject.make() Then -> expect(@sandwich).toHave("bread") Then -> expect(@sandwich).toHave("cheese") go run it on tryjasmine.com! http://is.gd/givensandwich
  18. describe "MakesSandwiches", -> Given -> @subject = new MakesSandwiches describe

    "#make", -> When -> @sandwich = @subject.make Then -> @sandwich.bread == “sourdough” Then -> @sandwich.cheese == “swiss” simple boolean Thens
  19. describe "MakesSandwiches", -> Given -> @subject = new MakesSandwiches describe

    "#make", -> When -> @sandwich = @subject.make Then( -> @sandwich.bread == “sourdough”) .Then( -> @sandwich.cheese == “swiss”) idempotent Thens
  20. describe "MakesSandwiches", -> Given -> @subject = new MakesSandwiches describe

    "#make", -> When -> @sandwich = @subject.make Then( -> @sandwich.bread == “sourdough”) .Then( -> @sandwich.cheese == “swiss”) idempotent Thens 2x of fast is fast!