|
7 | 7 | let(:input) { '' }
|
8 | 8 | let(:context) { described_class.new(config, args, input) }
|
9 | 9 |
|
| 10 | + describe '#setup_environment' do |
| 11 | + subject { context.setup_environment } |
| 12 | + |
| 13 | + context 'when there are no staged changes' do |
| 14 | + around do |example| |
| 15 | + repo do |
| 16 | + `echo "Hello World" > tracked-file` |
| 17 | + `git add tracked-file` |
| 18 | + `git commit -m "Add tracked-file"` |
| 19 | + `echo "Hello Again" > untracked-file` |
| 20 | + example.run |
| 21 | + end |
| 22 | + end |
| 23 | + |
| 24 | + it 'keeps already-committed files' do |
| 25 | + subject |
| 26 | + File.open('tracked-file', 'r').read == 'Hello World' |
| 27 | + end |
| 28 | + |
| 29 | + it 'keeps untracked files' do |
| 30 | + subject |
| 31 | + File.open('untracked-file', 'r').read == 'Hello Again' |
| 32 | + end |
| 33 | + |
| 34 | + it 'keeps modification times the same' do |
| 35 | + expect { subject }. |
| 36 | + to_not change { [File.mtime('tracked-file'), File.mtime('untracked-file')] } |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + context 'when there are staged changes' do |
| 41 | + around do |example| |
| 42 | + repo do |
| 43 | + `echo "Hello World" > tracked-file` |
| 44 | + `git add tracked-file` |
| 45 | + `git commit -m "Add tracked-file"` |
| 46 | + `echo "Hello Again" > untracked-file` |
| 47 | + `echo "Some more text" >> tracked-file` |
| 48 | + `git add tracked-file` |
| 49 | + `echo "Yet some more text" >> tracked-file` |
| 50 | + example.run |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + it 'keeps staged changes' do |
| 55 | + subject |
| 56 | + File.open('tracked-file', 'r').read == 'Hello WorldSome more text' |
| 57 | + end |
| 58 | + |
| 59 | + it 'keeps untracked files' do |
| 60 | + subject |
| 61 | + File.open('untracked-file', 'r').read == 'Hello Again' |
| 62 | + end |
| 63 | + |
| 64 | + it 'keeps modification times the same' do |
| 65 | + expect { subject }. |
| 66 | + to_not change { [File.mtime('tracked-file'), File.mtime('untracked-file')] } |
| 67 | + end |
| 68 | + end |
| 69 | + end |
| 70 | + |
| 71 | + describe '#cleanup_environment' do |
| 72 | + subject { context.cleanup_environment } |
| 73 | + |
| 74 | + before do |
| 75 | + context.setup_environment |
| 76 | + end |
| 77 | + |
| 78 | + context 'when there were no staged changes' do |
| 79 | + around do |example| |
| 80 | + repo do |
| 81 | + `echo "Hello World" > tracked-file` |
| 82 | + `git add tracked-file` |
| 83 | + `git commit -m "Add tracked-file"` |
| 84 | + `echo "Hello Again" > untracked-file` |
| 85 | + example.run |
| 86 | + end |
| 87 | + end |
| 88 | + |
| 89 | + it 'keeps already-committed files' do |
| 90 | + subject |
| 91 | + File.open('tracked-file', 'r').read.should == "Hello World\n" |
| 92 | + end |
| 93 | + |
| 94 | + it 'keeps untracked files' do |
| 95 | + subject |
| 96 | + File.open('untracked-file', 'r').read.should == "Hello Again\n" |
| 97 | + end |
| 98 | + |
| 99 | + it 'keeps modification times the same' do |
| 100 | + expect { subject }. |
| 101 | + to_not change { [File.mtime('tracked-file'), File.mtime('untracked-file')] } |
| 102 | + end |
| 103 | + end |
| 104 | + |
| 105 | + context 'when there were staged changes' do |
| 106 | + around do |example| |
| 107 | + repo do |
| 108 | + `echo "Hello World" > tracked-file` |
| 109 | + `git add tracked-file` |
| 110 | + `git commit -m "Add tracked-file"` |
| 111 | + `echo "Hello Again" > untracked-file` |
| 112 | + `echo "Some more text" >> tracked-file` |
| 113 | + `git add tracked-file` |
| 114 | + `echo "Yet some more text" >> tracked-file` |
| 115 | + example.run |
| 116 | + end |
| 117 | + end |
| 118 | + |
| 119 | + it 'restores the unstaged changes' do |
| 120 | + subject |
| 121 | + File.open('tracked-file', 'r').read. |
| 122 | + should == "Hello World\nSome more text\nYet some more text\n" |
| 123 | + end |
| 124 | + |
| 125 | + it 'keeps untracked files' do |
| 126 | + subject |
| 127 | + File.open('untracked-file', 'r').read.should == "Hello Again\n" |
| 128 | + end |
| 129 | + |
| 130 | + it 'keeps modification times the same' do |
| 131 | + expect { subject }. |
| 132 | + to_not change { [File.mtime('tracked-file'), File.mtime('untracked-file')] } |
| 133 | + end |
| 134 | + end |
| 135 | + end |
| 136 | + |
10 | 137 | describe '#modified_files' do
|
11 | 138 | subject { context.modified_files }
|
12 | 139 |
|
|
0 commit comments