renmov 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,44 @@
1
+ Feature: Options
2
+ As a user of `renmov`
3
+ In order to get the results desired
4
+ I want the command line arguments to work properly
5
+
6
+ Scenario: verbose (-v)
7
+ Given an empty file named "TV.Show.S01E02.HDTV.x264-LOL.mp4"
8
+ When I successfully run `renmov -v TV.Show.S01E02.HDTV.x264-LOL.mp4`
9
+ Then a file named "TV.Show.S01E02.HDTV.x264-LOL.mp4" should not exist
10
+ And a file named "tv.show.s01e02.mp4" should exist
11
+ And the output should contain:
12
+ """
13
+ mv TV.Show.S01E02.HDTV.x264-LOL.mp4 tv.show.s01e02.mp4
14
+ """
15
+
16
+ Scenario: verbose (--verbose)
17
+ Given an empty file named "TV.Show.S01E02.HDTV.x264-LOL.mp4"
18
+ When I successfully run `renmov --verbose TV.Show.S01E02.HDTV.x264-LOL.mp4`
19
+ Then a file named "TV.Show.S01E02.HDTV.x264-LOL.mp4" should not exist
20
+ And a file named "tv.show.s01e02.mp4" should exist
21
+ And the output should contain:
22
+ """
23
+ mv TV.Show.S01E02.HDTV.x264-LOL.mp4 tv.show.s01e02.mp4
24
+ """
25
+
26
+ Scenario: noop (-n)
27
+ Given an empty file named "TV.Show.S01E02.HDTV.x264-LOL.mp4"
28
+ When I successfully run `renmov -n TV.Show.S01E02.HDTV.x264-LOL.mp4`
29
+ Then a file named "tv.show.s01e02.mp4" should not exist
30
+ And a file named "TV.Show.S01E02.HDTV.x264-LOL.mp4" should exist
31
+ And the output should contain:
32
+ """
33
+ mv TV.Show.S01E02.HDTV.x264-LOL.mp4 tv.show.s01e02.mp4
34
+ """
35
+
36
+ Scenario: noop (--noop)
37
+ Given an empty file named "TV.Show.S01E02.HDTV.x264-LOL.mp4"
38
+ When I successfully run `renmov --noop TV.Show.S01E02.HDTV.x264-LOL.mp4`
39
+ Then a file named "tv.show.s01e02.mp4" should not exist
40
+ And a file named "TV.Show.S01E02.HDTV.x264-LOL.mp4" should exist
41
+ And the output should contain:
42
+ """
43
+ mv TV.Show.S01E02.HDTV.x264-LOL.mp4 tv.show.s01e02.mp4
44
+ """
data/lib/renmov/cli.rb CHANGED
@@ -7,11 +7,12 @@ module Renmov
7
7
  attr_reader :args
8
8
  attr_accessor :options
9
9
  attr_accessor :filenames
10
+ attr_accessor :renamer
10
11
 
11
12
  def initialize(args = ARGV, renamer = BasicRenamer)
12
13
  @args = args
13
14
  @filenames = []
14
- @options = { verbose: false }
15
+ @options = { verbose: false, noop: false }
15
16
  @renamer = renamer
16
17
  end
17
18
 
@@ -20,20 +21,28 @@ module Renmov
20
21
  opts.on('-v', '--verbose', 'Output more information') do
21
22
  options[:verbose] = true
22
23
  end
24
+
25
+ opts.on('-n', '--noop', 'Output actions without invoking them') do
26
+ options[:noop] = true
27
+ options[:verbose] = true
28
+ end
23
29
  end
24
30
 
25
31
  self.filenames = optparse.parse! args
26
32
  end
27
33
 
28
34
  def run
29
- @filenames.each do |filename|
30
- dirname = File.dirname(filename)
31
- filename = File.basename(filename)
32
- renamer = @renamer.new(filename)
33
- newname = renamer.rename
34
- FileUtils.mv("#{dirname}/#{filename}",
35
- "#{dirname}/#{newname}",
36
- verbose: options[:verbose])
35
+ filenames.each do |filename|
36
+ dirname = "#{File.dirname(filename)}/"
37
+ dirname.gsub!(/\A\.\/\z/, '')
38
+
39
+ basename = File.basename(filename)
40
+ renamer_i = renamer.new(basename)
41
+ newname = "#{dirname}#{renamer_i.rename}"
42
+ FileUtils.mv(filename,
43
+ newname,
44
+ verbose: options[:verbose],
45
+ noop: options[:noop])
37
46
  end
38
47
  end
39
48
  end
@@ -1,3 +1,3 @@
1
1
  module Renmov
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -4,7 +4,8 @@ require 'fileutils'
4
4
  module Renmov
5
5
  describe CLI do
6
6
  describe '#parse_options' do
7
- let(:default_options) { { verbose: false } }
7
+ let(:default_options) { { verbose: false, noop: false } }
8
+
8
9
  before(:each) do
9
10
  @cli = CLI.new(options + filenames)
10
11
  @cli.parse_options
@@ -65,12 +66,50 @@ module Renmov
65
66
  end
66
67
  end
67
68
  end
69
+
70
+ context 'with noop option provided' do
71
+ let(:options) { ['-n'] }
72
+
73
+ context 'with no filenames provided' do
74
+ let(:filenames) { [] }
75
+
76
+ it 'merges verbose and noop with default options' do
77
+ @cli.options.should == default_options.merge(verbose: true,
78
+ noop: true)
79
+ end
80
+
81
+ it 'sets filenames to []' do
82
+ @cli.filenames.should == filenames
83
+ end
84
+ end
85
+
86
+ context 'with one filename provided' do
87
+ let(:filenames) { ['TV.Show.S01E02.HDTV.test.mp4'] }
88
+
89
+ it 'merges verbose and noop with default options' do
90
+ @cli.options.should == default_options.merge(verbose: true,
91
+ noop: true)
92
+ end
93
+
94
+ it 'sets filenames to filename provided' do
95
+ @cli.filenames.should == filenames
96
+ end
97
+ end
98
+ end
68
99
  end
69
100
 
70
101
  describe '#run' do
71
102
  let(:tmpdir) { File.expand_path('../../../tmp', __FILE__) }
103
+
72
104
  before(:each) do
73
- FileUtils.touch filenames
105
+ filenames.each do |filename|
106
+ FileUtils.rm(filename) if File.exists?(filename)
107
+ end
108
+ newnames.each do |newname|
109
+ FileUtils.rm(newname) if File.exists?(newname)
110
+ end
111
+
112
+ FileUtils.touch(filenames)
74
113
  cli = CLI.new(filenames)
75
114
  cli.parse_options
76
115
  cli.run
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: renmov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -68,6 +68,7 @@ extra_rdoc_files: []
68
68
  files:
69
69
  - Rakefile
70
70
  - bin/renmov
71
+ - features/options.feature
71
72
  - features/rename_files.feature
72
73
  - features/support/env.rb
73
74
  - lib/renmov.rb
@@ -102,8 +103,9 @@ rubyforge_project:
102
103
  rubygems_version: 1.8.24
103
104
  signing_key:
104
105
  specification_version: 3
105
- summary: renmov-0.0.1
106
+ summary: renmov-0.0.2
106
107
  test_files:
108
+ - features/options.feature
107
109
  - features/rename_files.feature
108
110
  - features/support/env.rb
109
111
  - spec/renmov/basic_renamer_spec.rb