File tree 1 file changed +45
-0
lines changed
spec/overcommit/hook/pre_commit
1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Overcommit ::Hook ::PreCommit ::FileSize do
6
+ let ( :config ) do
7
+ Overcommit ::ConfigurationLoader . default_configuration . merge (
8
+ Overcommit ::Configuration . new (
9
+ 'PreCommit' => {
10
+ 'FileSize' => {
11
+ 'size_limit_bytes' => 10
12
+ }
13
+ }
14
+ )
15
+ )
16
+ end
17
+
18
+ let ( :context ) { double ( 'context' ) }
19
+ subject { described_class . new ( config , context ) }
20
+ let ( :staged_file ) { 'filename.txt' }
21
+
22
+ before do
23
+ subject . stub ( :applicable_files ) . and_return ( [ staged_file ] )
24
+ end
25
+
26
+ around do |example |
27
+ repo do
28
+ File . open ( staged_file , 'w' ) { |f | f . write ( contents ) }
29
+ `git add "#{ staged_file } " > #{ File ::NULL } 2>&1`
30
+ example . run
31
+ end
32
+ end
33
+
34
+ context 'when a big file is committed' do
35
+ let ( :contents ) { 'longer than 10 bytes' }
36
+
37
+ it { should fail_hook }
38
+ end
39
+
40
+ context 'when a small file is committed' do
41
+ let ( :contents ) { 'short' }
42
+
43
+ it { should_not fail_hook }
44
+ end
45
+ end
You can’t perform that action at this time.
0 commit comments