File: disk_usage.feature

package info (click to toggle)
ruby-aruba 0.14.8-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,216 kB
  • sloc: ruby: 7,951; sh: 21; makefile: 12
file content (152 lines) | stat: -rw-r--r-- 4,294 bytes parent folder | download | duplicates (2)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
@unsupported-on-ruby-older-19
Feature: Report disk usage

  Sometimes you need to check, what amount of disk space a file consumes. We do
  NOT support "directories" with `#disk_usage`. This does not work reliably
  over different systems. Here can help `'#disk_usage`. But be careful, by
  default it uses a block size of "512" (physical block size) to calculate the
  usage. You may need to adjust this by using `Aruba.configure { |config|
  config.physical_block_size = 4_096 }`. Don't get confused, if you check the
  block size by using `File::Stat` (in ruby). It reports the block size of your
  filesystem, which can be "4_096" for example.

  We're gonna use the (correct) IEC-notation
  (https://en.wikipedia.org/wiki/Binary_prefix) here:

    \* kilo => kibi
    \* mega => mebi
    \* giga => gibi

  Background:
    Given I use a fixture named "cli-app"

  Scenario: Show disk usage for file
    Given a file named "spec/disk_usage_spec.rb" with:
    """ruby
    require 'spec_helper'

    RSpec.describe 'disk usage', :type => :aruba do
      let(:file) { 'file.txt' }

      before(:each) do 
        write_file file, 'a'
      end

      let(:size_of_single_block) { File::Stat.new(expand_path(file)).blksize }

      it { expect(disk_usage(file)).to eq size_of_single_block }
    end
    """
    When I run `rspec`
    Then the specs should all pass

  Scenario: Show disk usage for multiple files

    `#disk_usage` creates the sum of all given objects' sizes.

    Given a file named "spec/disk_usage_spec.rb" with:
    """ruby
    require 'spec_helper'

    RSpec.describe 'disk usage', :type => :aruba do
      let(:file1) { 'file1.txt' }
      let(:file2) { 'file2.txt' }

      before(:each) do 
        write_file file1, 'a'
        write_file file2, 'a'
      end

      let(:size_of_single_block) { File::Stat.new(expand_path(file1)).blksize }

      it { expect(disk_usage(file1, file2)).to eq size_of_single_block * 2 }
      it { expect(disk_usage([file1, file2])).to eq size_of_single_block * 2 }
    end
    """
    When I run `rspec`
    Then the specs should all pass

  Scenario: Convert reported disk usage to KibiByte
    Given a file named "spec/disk_usage_spec.rb" with:
    """ruby
    require 'spec_helper'

    RSpec.describe 'disk usage', :type => :aruba do
      let(:file) { 'file.txt' }

      before(:each) do 
        write_file file, 'a'
      end

      let(:converted_size) { File::Stat.new(expand_path(file)).blksize.to_f / 1_024 }

      it { expect(disk_usage(file).to_kibi_byte).to eq converted_size }
    end
    """
    When I run `rspec`
    Then the specs should all pass

  Scenario: Convert reported disk usage to MebiByte
    Given a file named "spec/disk_usage_spec.rb" with:
    """ruby
    require 'spec_helper'

    RSpec.describe 'disk usage', :type => :aruba do
      let(:file) { 'file.txt' }

      before(:each) do 
        write_file file, 'a'
      end

      let(:converted_size) { File::Stat.new(expand_path(file)).blksize.to_f / 1_024 / 1024 }

      it { expect(disk_usage(file).to_mebi_byte).to eq converted_size }
    end
    """
    When I run `rspec`
    Then the specs should all pass

  Scenario: Convert reported disk usage to GibiByte
    Given a file named "spec/disk_usage_spec.rb" with:
    """ruby
    require 'spec_helper'

    RSpec.describe 'disk usage', :type => :aruba do
      let(:file) { 'file.txt' }

      before(:each) do 
        write_file file, 'a'
      end

      let(:converted_size) { File::Stat.new(expand_path(file)).blksize.to_f / 1_024 / 1_024 / 1_024 }

      it { expect(disk_usage(file).to_gibi_byte).to eq converted_size }
    end
    """
    When I run `rspec`
    Then the specs should all pass

  Scenario: Compare two repored disk usages
    Given a file named "spec/disk_usage_spec.rb" with:
    """ruby
    require 'spec_helper'

    RSpec.describe 'disk usage', :type => :aruba do
      let(:file1) { 'file1.txt' }
      let(:file2) { 'file2.txt' }

      before(:each) do 
        write_file file1, 'a' * 10_000
        write_file file2, 'a'
      end

      before :each do
        @size1 = disk_usage(file1)
        @size2 = disk_usage(file2)
      end

      it { expect(@size1).to be > @size2 }
    end
    """
    When I run `rspec`
    Then the specs should all pass