This repository has been archived by the owner on Mar 1, 2019. It is now read-only.
forked from cucumber/aruba
-
Notifications
You must be signed in to change notification settings - Fork 1
/
have_file_content.feature
123 lines (94 loc) · 3.34 KB
/
have_file_content.feature
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
Feature: Check if file has content
If you need to check if a given file has content, you can use the
`have_file_content`-matcher. It accepts `Object`, `Regexp` or any other
`RSpec::Matcher`-matchers. It fails if file does not exist.
```ruby
require 'spec_helper'
RSpec.describe 'Check if file has content', :type => :aruba do
let(:file) { 'file.txt' }
let(:content) { 'Hello World' }
before(:each) { write_file(file, content) }
it { expect(file).to have_file_content content }
end
```
Background:
Given I use a fixture named "cli-app"
Scenario: Expect existing file with content
Given a file named "spec/file_with_content_spec.rb" with:
"""
require 'spec_helper'
RSpec.describe 'Check file content', :type => :aruba do
let(:file) { 'file.txt' }
let(:content) { 'Hello World' }
before(:each) { write_file(file, content) }
it { expect(file).to have_file_content content }
end
"""
When I run `rspec`
Then the specs should all pass
Scenario: Expect existing file with partial content
Given a file named "spec/file_with_content_spec.rb" with:
"""
require 'spec_helper'
RSpec.describe 'Check file content', :type => :aruba do
let(:file) { 'file.txt' }
let(:content) { 'Hello World' }
before(:each) { write_file(file, content) }
it { expect(file).to have_file_content /Hello/ }
end
"""
When I run `rspec`
Then the specs should all pass
Scenario: Expect existing file with partial content described by another matcher
Given a file named "spec/file_with_content_spec.rb" with:
"""
require 'spec_helper'
RSpec.describe 'Check file content', :type => :aruba do
let(:file) { 'file.txt' }
let(:content) { 'Hello World' }
before(:each) { write_file(file, content) }
it { expect(file).to have_file_content a_string_starting_with('Hello') }
end
"""
When I run `rspec`
Then the specs should all pass
Scenario: Expect multiple existing files with content
Given a file named "spec/file_with_content_spec.rb" with:
"""
require 'spec_helper'
RSpec.describe 'Check file content', :type => :aruba do
let(:files) { %w(file1.txt file2.txt) }
let(:content) { 'Hello World' }
before :each do
files.each { |f| write_file(f, content) }
end
it { expect(files).to all have_file_content content }
end
"""
When I run `rspec`
Then the specs should all pass
Scenario: Expect at least one file with content
Given a file named "spec/file_with_content_spec.rb" with:
"""
require 'spec_helper'
RSpec.describe 'Check file content', :type => :aruba do
let(:files) { %w(file1.txt file2.txt) }
let(:content) { 'Hello World' }
before(:each) { write_file(files.first, content) }
it { expect(files).to include a_file_having_content content }
end
"""
When I run `rspec`
Then the specs should all pass
Scenario: Fails if file does not exist
Given a file named "spec/file_with_content_spec.rb" with:
"""
require 'spec_helper'
RSpec.describe 'Check file content', :type => :aruba do
let(:file) { 'file.txt' }
let(:content) { 'Hello World' }
it { expect(file).to have_file_content content }
end
"""
When I run `rspec`
Then the specs should not all pass