File: spinach_adapter_spec.rb

package info (click to toggle)
ruby-knapsack 1.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,084 kB
  • sloc: ruby: 2,832; makefile: 4; sh: 3
file content (83 lines) | stat: -rw-r--r-- 2,645 bytes parent folder | download
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
78
79
80
81
82
83
describe Knapsack::Adapters::SpinachAdapter do
  context do
    it_behaves_like 'adapter'
  end

  describe 'bind methods' do
    let(:config) { double }
    let(:logger) { instance_double(Knapsack::Logger) }

    before do
      expect(Knapsack).to receive(:logger).and_return(logger)
    end

    describe '#bind_time_tracker' do
      let(:tracker) { instance_double(Knapsack::Tracker) }
      let(:global_time) { 'Global time: 01m 05s' }
      let(:test_path) { 'features/a.feature' }
      let(:scenario_data) do
        double(feature: double(filename: test_path))
      end

      it do
        allow(Knapsack).to receive(:tracker).and_return(tracker)

        expect(Spinach.hooks).to receive(:before_scenario).and_yield(scenario_data, nil)
        expect(described_class).to receive(:test_path).with(scenario_data).and_return(test_path)
        expect(tracker).to receive(:test_path=).with(test_path)
        expect(tracker).to receive(:start_timer)

        expect(Spinach.hooks).to receive(:after_scenario).and_yield
        expect(tracker).to receive(:stop_timer)

        expect(Spinach.hooks).to receive(:after_run).and_yield
        expect(Knapsack::Presenter).to receive(:global_time).and_return(global_time)
        expect(logger).to receive(:info).with(global_time)

        subject.bind_time_tracker
      end
    end

    describe '#bind_report_generator' do
      let(:report) { instance_double(Knapsack::Report) }
      let(:report_details) { 'Report details' }

      it do
        expect(Spinach.hooks).to receive(:after_run).and_yield

        expect(Knapsack).to receive(:report).and_return(report)
        expect(report).to receive(:save)

        expect(Knapsack::Presenter).to receive(:report_details).and_return(report_details)
        expect(logger).to receive(:info).with(report_details)

        subject.bind_report_generator
      end
    end

    describe '#bind_time_offset_warning' do
      let(:time_offset_warning) { 'Time offset warning' }
      let(:log_level) { :info }

      it do
        expect(Spinach.hooks).to receive(:after_run).and_yield

        expect(Knapsack::Presenter).to receive(:time_offset_warning).and_return(time_offset_warning)
        expect(Knapsack::Presenter).to receive(:time_offset_log_level).and_return(log_level)
        expect(logger).to receive(:log).with(log_level, time_offset_warning)

        subject.bind_time_offset_warning
      end
    end
  end

  describe '.test_path' do
    let(:scenario_data) do
      double(feature: double(filename: 'a.feature'))
    end

    subject { described_class.test_path(scenario_data) }

    it { should eql 'a.feature' }
  end
end