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. jasmine-given
    is for givers
    http://github.com/searls/jasmine-given

    View full-size slide

  2. @searls
    http://test-double.com

    View full-size slide

  3. 1st things
    1st

    View full-size slide

  4. thanks @jimweirich
    for rspec-given!

    View full-size slide

  5. a brief
    history

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  10. and so began our
    wonderful
    addiction to
    GREEN BARS

    View full-size slide

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

    View full-size slide

  12. 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();
    }

    View full-size slide

  13. 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

    View full-size slide

  14. 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

    View full-size slide

  15. 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

    View full-size slide

  16. 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

    View full-size slide

  17. 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

    View full-size slide

  18. 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

    View full-size slide

  19. 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

    View full-size slide

  20. 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

    View full-size slide

  21. 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

    View full-size slide

  22. 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")

    View full-size slide

  23. 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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  26. 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!

    View full-size slide

  27. @searls
    http://test-double.com

    View full-size slide