Slide 1

Slide 1 text

jasmine-given is for givers http://github.com/searls/jasmine-given

Slide 2

Slide 2 text

@searls http://test-double.com

Slide 3

Slide 3 text

1st things 1st

Slide 4

Slide 4 text

thanks @jimweirich for rspec-given!

Slide 5

Slide 5 text

a brief history

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

and so began our wonderful addiction to GREEN BARS

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

1 more thing

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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!

Slide 28

Slide 28 text

@searls http://test-double.com