test/exercism/config_test.rb in exercism-0.0.18 vs test/exercism/config_test.rb in exercism-0.0.19
- old
+ new
@@ -4,19 +4,35 @@
def path
'./test/fixtures'
end
+ def data
+ {
+ 'github_username' => 'bob',
+ 'key' => '7a7096c',
+ 'project_dir' => '/tmp'
+ }
+ end
+
def key
- '7a7096c'
+ data['key']
end
+ def write_config_file(path, info = {})
+ Exercism::Config.write(path, data.merge!(info))
+ end
+
def teardown
if File.exists?('./test/fixtures/.exercism')
FileUtils.rm('./test/fixtures/.exercism')
end
+ if File.exists?('./test/fixtures/.config/exercism')
+ FileUtils.rm_r('./test/fixtures/.config')
+ end
+
if File.exists?('./test/fixtures/some/project/dir')
FileUtils.rm_r('./test/fixtures/some')
end
end
@@ -25,41 +41,36 @@
assert_equal 'alice', config.github_username
assert_equal '634abfb095ed621e1c793c9875fcd9fda455ea90', config.key
assert_equal '/tmp', config.project_dir
end
+ def test_reads_from_alternate_path_config_file_when_default_is_missing
+ write_config_file('./test/fixtures/.config')
+ Exercism::Config.stub(:alternate_path, './test/fixtures/.config') do
+ config = Exercism::Config.read(path)
+ assert_equal 'bob', config.github_username
+ assert_equal key, config.key
+ assert_equal '/tmp', config.project_dir
+ end
+ end
+
def test_write_config_file
- data = {
- 'github_username' => 'bob',
- 'key' => key,
- 'project_dir' => '/tmp'
- }
- config = Exercism::Config.write(path, data)
+ config = write_config_file(path)
assert_equal 'bob', config.github_username
assert_equal key, config.key
assert_equal '/tmp', config.project_dir
end
def test_delete_config_file
- data = {
- 'github_username' => 'bob',
- 'key' => key,
- 'project_dir' => '/tmp'
- }
- config = Exercism::Config.write(path, data)
+ config = write_config_file(path)
filename = config.file
config.delete
assert !File.exists?(filename)
end
def test_write_directory_if_missing
- project_dir = './test/fixtures/some/project/dir'
- data = {
- 'github_username' => 'bob',
- 'key' => key,
- 'project_dir' => project_dir
- }
- Exercism::Config.write(path, data)
- assert File.exist? project_dir
+ data = {'project_dir' => './test/fixtures/some/project/dir'}
+ write_config_file(path, data)
+ assert File.exist?(data['project_dir'])
end
end