|
22 | 22 | app_path = File.join(base_dir, 'app') |
23 | 23 | Dir.mkdir(app_path) |
24 | 24 | FileUtils.chmod(0o700, app_path) |
| 25 | + # Mock the mtime to eliminate the potential for a different timezone output in the failure message |
| 26 | + mock_file_stat(app_path, mtime: mocked_now - 200) |
25 | 27 |
|
26 | | - matcher = be_dir(mode: '0755') |
| 28 | + matcher = be_dir(mtime: be_within(50).of(mocked_now)) |
27 | 29 | matcher.matches?(app_path) |
28 | 30 |
|
29 | 31 | expected_message = <<~MSG.chomp |
30 | 32 | #{app_path} was not as expected: |
31 | | - expected mode to be "0755", but it was "0700" |
| 33 | + expected mtime to be within 50 of 1967-03-15 00:16:00.000000000 -0700, but it was 1967-03-15 00:12:40 -0700 |
32 | 34 | MSG |
33 | 35 | expect(matcher.failure_message).to eq(expected_message) |
34 | 36 | end |
|
60 | 62 | setup_path = File.join(bin_path, 'setup') |
61 | 63 | Dir.mkdir(bin_path) |
62 | 64 | File.write(setup_path, '#!/bin/sh') |
63 | | - FileUtils.chmod(0o755, setup_path) |
64 | | - mock_file_stat(setup_path, uid: 9999, mode: 0o100755) |
65 | | - mock_user_name(9999, 'testuser') |
| 65 | + # Mock the mtime to eliminate the potential for a different timezone output in the failure message |
| 66 | + mock_file_stat(setup_path, mtime: mocked_now - 1, size: 9) |
66 | 67 |
|
67 | 68 | matcher = be_dir.containing( |
68 | | - file('setup', mode: '0644', owner: 'root') |
| 69 | + file('setup', mtime: mocked_now, size: be_zero) |
69 | 70 | ) |
70 | 71 | matcher.matches?(bin_path) |
71 | 72 |
|
72 | 73 | expected_message = <<~MSG.chomp |
73 | 74 | #{bin_path} was not as expected: |
74 | 75 | - setup |
75 | | - expected mode to be "0644", but it was "0755" |
76 | | - expected owner to be "root", but it was "testuser" |
| 76 | + expected mtime to be 1967-03-15 00:16:00 -0700, but it was 1967-03-15 00:15:59 -0700 |
| 77 | + expected size to be zero, but it was 9 |
77 | 78 | MSG |
78 | 79 | expect(matcher.failure_message).to eq(expected_message) |
79 | 80 | end |
|
92 | 93 | FileUtils.mkdir_p(lib_dir) |
93 | 94 | File.write(setup_path, '#!/bin/sh') |
94 | 95 | File.write(version_path, version_rb_content) |
95 | | - FileUtils.chmod(0o755, setup_path) |
96 | | - |
97 | | - mock_file_stat(setup_path, uid: 9999, mode: 0o100755) |
98 | | - mock_user_name(9999, 'owner') |
| 96 | + mock_file_stat(setup_path, mtime: mocked_now - 11, size: 9) |
99 | 97 |
|
100 | 98 | matcher = be_dir.containing( |
101 | 99 | dir('bin').containing( |
102 | | - file('setup', mode: '0644', owner: 'root') |
| 100 | + file('setup', mtime: be_within(10).of(mocked_now), size: be_zero) |
103 | 101 | ), |
104 | 102 | dir('lib').containing( |
105 | 103 | dir('new_project').containing( |
|
112 | 110 | expected_message = <<~MSG.chomp |
113 | 111 | #{base_dir} was not as expected: |
114 | 112 | - bin/setup |
115 | | - expected mode to be "0644", but it was "0755" |
116 | | - expected owner to be "root", but it was "owner" |
| 113 | + expected mtime to be within 10 of 1967-03-15 00:16:00.000000000 -0700, but it was 1967-03-15 00:15:49 -0700 |
| 114 | + expected size to be zero, but it was 9 |
117 | 115 | - lib/new_project/version.rb |
118 | 116 | expected content to include "VERSION = \\"0.1.1\\"", but it was #{version_rb_content.inspect} |
119 | 117 | MSG |
|
0 commit comments