summaryrefslogtreecommitdiff
path: root/vendor/bandit/specs/fuzzbox.spec.cpp
blob: 6515a5544d5d4d1f3831a29aad954a7577be160f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <specs/specs.h>

namespace fuzzbox {

  typedef enum {
    clean,
    distorted
  } sounds;

  struct fuzzbox
  {
    fuzzbox() : sound_(sounds::clean)
    {}

    void flip()
    {
      sound_ = sounds::distorted;
    }

    sounds sound()
    {
      return sound_;
    }

    private:
    sounds sound_;
  };
  typedef std::unique_ptr<fuzzbox> fuzzbox_ptr;

  struct guitar
  {
    void add_effect(fuzzbox* effect)
    {
      effect_ = effect;
    }

    sounds sound()
    {
      return effect_->sound();
    }

    private:
    fuzzbox* effect_;
  };
  typedef std::unique_ptr<guitar> guitar_ptr;
  
go_bandit([](){

    describe("fuzzbox:", [](){
      guitar_ptr guitar;
      fuzzbox_ptr fuzzbox;

      before_each([&](){
        guitar = guitar_ptr(new struct guitar());
        fuzzbox = fuzzbox_ptr(new struct fuzzbox());
        guitar->add_effect(fuzzbox.get());
      });

      it("starts in clean mode", [&](){
        AssertThat(guitar->sound(), Equals(sounds::clean));
      });

      describe("in distorted mode", [&](){

        before_each([&](){
          fuzzbox->flip();
        });

        it("sounds distorted", [&](){
          AssertThat(guitar->sound(), Equals(sounds::distorted));
        });
      });
    });

});

}