Repository: vortec/versionbump

Issue:
FileBump does not correctly adjust the target file size
When adjusting the version in a file, the file size is not correctly adjusted.

For example:

File contents before bump:
```
0.1.22222
```

Command used:
```
versionbump -c 0.1.22222 minor version.txt
```

File contents after bump:
```
0.2.0
222
```

Ideally the file contents would be:
```
0.2.0
```

Discussion:

Patch:
diff --git a/.travis.yml b/.travis.yml
index 2ab01b1..b7ed065 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,13 +3,9 @@ python:
     - 2.7
     - 3.4
     - pypy
-before_install:
-  - pip install codecov
 install:
     - pip install .
     - pip install behave dont-fudge-up
 script:
     - py.test -v tests
     - behave tests/features
-after_success:
-  - codecov
diff --git a/versionbump/filebump.py b/versionbump/filebump.py
index 65713cb..98d29f9 100644
--- a/versionbump/filebump.py
+++ b/versionbump/filebump.py
@@ -32,6 +32,7 @@ class FileBump(object):
     def write_cache_to_file(self):
         self.fo.seek(0)
         self.fo.write(self.file_cache)
+        self.fo.truncate()
 
     def replace_version_in_cache(self, old_version, new_version):
         self.file_cache = self.file_cache.replace(old_version, new_version)


Test patch:
diff --git a/tests/unit/test_filebump.py b/tests/unit/test_filebump.py
index 7bddb5f..12bc26f 100644
--- a/tests/unit/test_filebump.py
+++ b/tests/unit/test_filebump.py
@@ -51,3 +51,12 @@ def test_it_doesnt_find_the_version():
     empty_fo = StringIO('')
     with pytest.raises(ValueError):
         FileBump(empty_fo, '1.2.3')
+
+
+def test_it_truncates_the_file():
+    version = '0.0.111'
+    fo = StringIO(version)
+    fb = FileBump(fo, version)
+    fb.bump('minor')
+    fo.seek(0)
+    assert fo.read() == '0.1.0'