File: cd.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 (184 lines) | stat: -rw-r--r-- 4,861 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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
Feature: Change current working directory

  If you need to run some code in a different directory you can use the `cd`
  command. It comes in two flavors:

  \* First can simply use `cd 'some-dir'`
  \* Second can use the block notation `cd('some-dir') { Dir.getwd }`

  If you chose to use the latter one, the result of your block is returned. The
  current working directory is only changed for the code inside the block -
  it's use is side effect free.

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

  Scenario: Existing directory
    Given a file named "spec/cd_spec.rb" with:
    """ruby
    require 'spec_helper'

    RSpec.describe 'cd to directory', :type => :aruba do
      before(:each) do 
        create_directory 'new_dir.d'
        cd 'new_dir.d'
      end

      before(:each) { run_command_and_stop 'pwd' }

      it { expect(last_command_started.output).to include 'new_dir.d' }
    end
    """
    When I run `rspec`
    Then the specs should all pass

  Scenario: Non-Existing directory
    Given a file named "spec/cd_spec.rb" with:
    """ruby
    require 'spec_helper'

    RSpec.describe 'cd to directory', :type => :aruba do
      before(:each) { cd 'new_dir.d' }
      before(:each) { run_command_and_stop 'pwd' }

      it { expect(last_command_started.output).to include 'new_dir.d' }
      it { expect(last_command_started).to be_executed_in_time }
    end
    """
    When I run `rspec`
    Then the specs should not pass

  Scenario: With block in it-block
    Given a file named "spec/cd_spec.rb" with:
    """ruby
    require 'spec_helper'

    RSpec.describe 'cd to directory', :type => :aruba do
      before(:each) do
        create_directory 'new_dir.d/subdir.d'
      end

      it do
        cd('new_dir.d/subdir.d') { expect(Dir.getwd).to include 'new_dir.d/subdir.d'  }
      end
    end
    """
    When I run `rspec`
    Then the specs should all pass

  Scenario: With block in before-block

    Running `cd` with a block does not change:

    \* The current directory - `Dir.getwd`
    \* Aruba's current directory

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

    RSpec.describe 'cd to directory', :type => :aruba do
      before(:each) do
        create_directory 'new_dir.d/subdir.d'
      end

      before :each do
        cd('new_dir.d/subdir.d') do
          # you code
        end
      end

      it { expect(Dir.getwd).not_to include 'new_dir.d/subdir.d' }
      it { expect(expand_path('.')).not_to include 'new_dir.d/subdir.d' }
    end
    """
    When I run `rspec`
    Then the specs should all pass

  Scenario: The result of the block is returned

    If you need to run some code in a different directory, you can also use the
    block-notation of `cd`.

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

    RSpec.describe 'cd to directory', :type => :aruba do
      before(:each) do
        create_directory 'new_dir.d/subdir.d'
      end

      before :each do
        @my_output = cd('new_dir.d/subdir.d') { Dir.getwd }
      end

      it { expect(@my_output).to include 'new_dir.d/subdir.d' }
    end
    """
    When I run `rspec`
    Then the specs should all pass

  Scenario: It changes the PWD- and OLDPWD-ENV-variable for a given block

    If you need to run some code in a different directory, you can also use the
    block-notation of `cd`.

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

    RSpec.describe 'cd to directory', :type => :aruba do
      before(:each) do
        create_directory 'new_dir.d'
      end

      before :each do
        cd('new_dir.d/') do
          @pwd    = ENV['PWD'] 
          @oldpwd = ENV['OLDPWD'] 
        end
      end

      it { expect(@pwd).to end_with 'new_dir.d' }
      it { expect(@oldpwd).to end_with 'cli-app' }
    end
    """
    When I run `rspec`
    Then the specs should all pass

  Scenario: Nested cd calls

    If you need to run some code in a different directory, you can also use the
    block-notation of `cd`.

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

    RSpec.describe 'cd to directory', :type => :aruba do
      before(:each) do
        create_directory 'new_dir.d/subdir.d'
      end

      before :each do
        cd('new_dir.d') do
          @oldpwd_1 = ENV['OLDPWD'] 
          @pwd_1    = ENV['PWD'] 

          cd('subdir.d') do
            @oldpwd_2 = ENV['OLDPWD'] 
            @pwd_2    = ENV['PWD'] 
          end
        end
      end

      it { expect(@oldpwd_1).to be_end_with 'cli-app' }
      it { expect(@pwd_1).to be_end_with 'new_dir.d' }

      it { expect(@oldpwd_2).to be_end_with 'new_dir.d' }
      it { expect(@pwd_2).to be_end_with 'subdir.d' }
    end
    """
    When I run `rspec`
    Then the specs should all pass