File: report_disk_usage.feature

package info (click to toggle)
ruby-aruba 2.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,972 kB
  • sloc: ruby: 7,151; javascript: 6,850; makefile: 5
file content (166 lines) | stat: -rw-r--r-- 4,526 bytes parent folder | download | duplicates (3)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
Feature: Report disk usage

  Sometimes you need to check, what amount of disk space a file consumes.

  This is useful, since many tiny files will usually take up a lot more disk
  space than their sizes suggest.

  While not be very accurate, `'#disk_usage` helps estimate this "real"
  allocated size on disk.

  NOTE 1: currently "directories" are NOT supported.

  NOTE 2: Aruba assumes the 'physical block size' is 512 bytes. (It usually is).

  If your OS/filesystem doesn't report the number of blocks used (and your
  allocation unit size is not 4096 bytes), you can change the default "block
  size" Aruba uses for calculations:

  E.g. for a 32kB "allocation unit size" and 16 blocks used for a tiny file
  (check `File::Stat.blocks` reported by Ruby), just divide the
  two numbers to get the "physical block size" you need to set:

  `Aruba.configure { |config| config.physical_block_size = 32_768 / 16 }`.


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