code2rubylearning 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -11,7 +11,7 @@ doc/
11
11
  rdoc
12
12
  lib/bundler/man
13
13
  spec/reports
14
- config.yaml
14
+ spec/spec_config.rb
15
15
  pkg
16
16
  test/tmp
17
17
  test/version_tmp
data/Gemfile CHANGED
@@ -40,7 +40,6 @@ group :test do
40
40
  gem 'minitest-matchers'
41
41
  gem 'guard-minitest', '0.5.0'
42
42
  gem 'guard', "~> 1.6.0"
43
- gem 'guard-rspec', "~> 2.3.1"
44
43
  gem 'simplecov', :require => false, :group => :test
45
44
  end
46
45
 
@@ -15,10 +15,10 @@ begin
15
15
  options[:stdout] = true
16
16
  end
17
17
 
18
- options[:combine] = false
19
- opt.on( '-c', '--combine', 'Combine multiple files into one ( not yet implemented )' ) do
20
- options[:combine] = true
21
- end
18
+ # options[:combine] = false
19
+ # opt.on( '-c', '--combine', 'Combine multiple files into one ( not yet implemented )' ) do
20
+ # options[:combine] = true
21
+ # end
22
22
 
23
23
  options[:filenames] = true
24
24
  opt.on( '-f', '--nofilenames', 'Suppress filename line in output' ) do
@@ -19,7 +19,7 @@ module Code2rubylearning
19
19
  end
20
20
 
21
21
  if options[:prg_link]
22
- @buffer << "<a href=\"https://github.com/rudicode/code2rubylearning/wiki\">Posted with code2rubylearning v#{ VERSION }</a>\n"
22
+ @buffer << %Q|<a href="https://github.com/rudicode/code2rubylearning/wiki">Posted with code2rubylearning v#{ VERSION }</a>\n|
23
23
  end
24
24
 
25
25
  Clippy.copy @buffer unless @buffer.empty?
@@ -21,13 +21,26 @@ module Code2rubylearning
21
21
  end
22
22
  end
23
23
 
24
- # TODO
25
24
  # Sets the @type for this file
26
25
  # check extension for known types
27
26
  # if extension fails try checking the first line
28
27
  # it may contain #! and give a clue.
29
28
  def identify_file_type
30
- @type = "ruby"
29
+ @type = "text"
30
+
31
+ data_lines = @data.split("\n")
32
+
33
+ # check for a ruby file
34
+ if @name.include?(".rb") || data_lines.first.include?("#!") && data_lines.first.include?("ruby")
35
+ @type = "ruby"
36
+ end
37
+
38
+ # check for a python file
39
+ if @name.include?(".py") || data_lines.first.include?("#!") && data_lines.first.include?("python")
40
+ @type = "python"
41
+ end
42
+
31
43
  end
44
+
32
45
  end
33
46
  end
@@ -1,3 +1,3 @@
1
1
  module Code2rubylearning
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -0,0 +1,4 @@
1
+ #! /usr/bin/env ruby
2
+ def hello
3
+ "Hello"
4
+ end
@@ -0,0 +1,3 @@
1
+ #! /usr/bin/sh
2
+ #some shell scripting here
3
+ #
@@ -0,0 +1,4 @@
1
+ #! /usr/bin/env python
2
+ # represents a python file with shbang
3
+ print "Hello, World!\n"
4
+
@@ -0,0 +1,3 @@
1
+ # represents a python file without shbang
2
+ print "Hello, World!\n"
3
+
@@ -0,0 +1 @@
1
+ def hello; "Hello World!"; end
@@ -12,14 +12,41 @@ describe "FileHandling" do
12
12
  end
13
13
 
14
14
  it "should set the data to the contents of the file" do
15
- expected = "def hello\n \"Hello\"\nend\n"
15
+ expected = %Q|def hello\n "Hello"\nend\n|
16
16
  @valid_file.data.must_equal expected
17
17
  end
18
18
 
19
- it "should set the type to the correct programming language" do
19
+ it "should set the type to ruby" do
20
20
  expected = "ruby"
21
21
  @valid_file.type.must_equal expected
22
22
  end
23
+
24
+ it "should set the type to ruby" do
25
+ @ruby_file_without_extension = "spec/assets/file-4"
26
+ @ruby_file = FileHandling.new(@ruby_file_without_extension)
27
+ expected = "ruby"
28
+ @ruby_file.type.must_equal expected
29
+ end
30
+
31
+ it "unknown files should default to text" do
32
+ @unknown = "spec/assets/file-5"
33
+ @unknown_file = FileHandling.new(@unknown)
34
+ expected = "text"
35
+ @unknown_file.type.must_equal expected
36
+ end
37
+
38
+ it "should set the type to python" do
39
+ @python_file_without_extension = "spec/assets/file-python"
40
+ @python_file_with_extension = "spec/assets/file-python.py"
41
+ @python = FileHandling.new(@python_file_without_extension)
42
+ @python_ext = FileHandling.new(@python_file_with_extension)
43
+
44
+ expected = "python"
45
+
46
+ @python.type.must_equal expected
47
+ @python_ext.type.must_equal expected
48
+ end
49
+
23
50
  end
24
51
 
25
52
  describe "invalid files" do
@@ -9,7 +9,7 @@ describe Code2rubylearning do
9
9
  files = ["spec/assets/file-1.rb"]
10
10
  from_clipboard = Code2rubylearning.start files, @options
11
11
 
12
- from_clipboard.must_equal "[code ruby]\r\ndef hello\r\n \"Hello\"\r\nend\r\n[/code]\r\n"
12
+ from_clipboard.must_equal %Q|[code ruby]\r\ndef hello\r\n "Hello"\r\nend\r\n[/code]\r\n|
13
13
 
14
14
  end
15
15
 
@@ -17,7 +17,7 @@ describe Code2rubylearning do
17
17
  files = ["spec/assets/file-1.rb", "spec/assets/file-2.rb"]
18
18
  from_clipboard = Code2rubylearning.start files, @options
19
19
 
20
- correct_response = "[code ruby]\r\ndef hello\r\n \"Hello\"\r\nend\r\n[/code]\r\n[code ruby]\r\ndef there\r\n \"There\"\r\nend\r\n[/code]\r\n"
20
+ correct_response = %Q|[code ruby]\r\ndef hello\r\n "Hello"\r\nend\r\n[/code]\r\n[code ruby]\r\ndef there\r\n "There"\r\nend\r\n[/code]\r\n|
21
21
  from_clipboard.must_equal correct_response
22
22
 
23
23
  end
@@ -26,8 +26,8 @@ describe Code2rubylearning do
26
26
  @options = { :prg_link => true }
27
27
  files = ["spec/assets/file-1.rb", "spec/assets/file-2.rb"]
28
28
  from_clipboard = Code2rubylearning.start files, @options
29
-
30
- correct_response = "<a href=\"https://github.com/rudicode/code2rubylearning/wiki\">Posted with code2rubylearning v"
29
+
30
+ correct_response = %Q|<a href="https://github.com/rudicode/code2rubylearning/wiki">Posted with code2rubylearning v|
31
31
  from_clipboard.must_include correct_response
32
32
 
33
33
  end
@@ -0,0 +1,13 @@
1
+ # Minitest Reporters Selection
2
+ # Reporter choices are case sensitive!
3
+ # uncommet the one you wish to use
4
+
5
+ Option = {
6
+ # report_style: "Default",
7
+ report_style: "Spec",
8
+ # report_style: "Progress",
9
+ # report_style: "Guard",
10
+ # report_style: "RubyMine",
11
+ # report_style: "RubyMate",
12
+ }
13
+
@@ -6,20 +6,14 @@ require "bundler/setup"
6
6
  require 'minitest/autorun'
7
7
  require 'minitest/reporters'
8
8
  require "minitest/matchers"
9
- require 'yaml'
10
9
 
11
- begin
12
- choice = YAML.load_file( 'config.yaml' )
13
- MiniTest::Reporters.use!(eval("MiniTest::Reporters::#{choice}Reporter.new"))
14
- rescue NameError, Errno::ENOENT
15
- STDERR.puts <<-EOWARNING
16
- #{'+-' * 33}
17
- You either don't have a config.yaml file in your project root, or
18
- you need to uncomment one of the choices from the menu.
19
- #{'+-' * 33}
20
- EOWARNING
21
- raise
22
- end
10
+ # To select a different reporter copy the spec/spec_config.rb.example to
11
+ # spec/spec_config.rb and select the reporter you wish to use.
12
+ File.exists?('spec/spec_config.rb') ?
13
+ require( 'spec_config') :
14
+ Option = {report_style: "Default"}
15
+ MiniTest::Reporters.use!(eval("MiniTest::Reporters::#{Option[:report_style]}Reporter.new"))
16
+
23
17
  require('code2rubylearning')
24
18
  require('code2rubylearning/version')
25
19
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code2rubylearning
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-10 00:00:00.000000000 Z
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: clippy
@@ -45,7 +45,6 @@ files:
45
45
  - Rakefile
46
46
  - bin/code2rubylearning
47
47
  - code2rubylearning.gemspec
48
- - config.yaml.example
49
48
  - lib/code2rubylearning.rb
50
49
  - lib/code2rubylearning/filehandling.rb
51
50
  - lib/code2rubylearning/filter.rb
@@ -53,10 +52,16 @@ files:
53
52
  - spec/assets/file-1.rb
54
53
  - spec/assets/file-2.rb
55
54
  - spec/assets/file-3.rb
55
+ - spec/assets/file-4
56
+ - spec/assets/file-5
57
+ - spec/assets/file-python
58
+ - spec/assets/file-python.py
59
+ - spec/assets/hello.rb
56
60
  - spec/code2rubylearning/filehandling_spec.rb
57
61
  - spec/code2rubylearning/filter_spec.rb
58
62
  - spec/code2rubylearning/version_spec.rb
59
63
  - spec/code2rubylearning_spec.rb
64
+ - spec/spec_config.rb.example
60
65
  - spec/spec_helper.rb
61
66
  homepage: https://github.com/rudicode/code2rubylearning
62
67
  licenses: []
@@ -70,12 +75,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
75
  - - ! '>='
71
76
  - !ruby/object:Gem::Version
72
77
  version: '0'
78
+ segments:
79
+ - 0
80
+ hash: 3155921660826552801
73
81
  required_rubygems_version: !ruby/object:Gem::Requirement
74
82
  none: false
75
83
  requirements:
76
84
  - - ! '>='
77
85
  - !ruby/object:Gem::Version
78
86
  version: '0'
87
+ segments:
88
+ - 0
89
+ hash: 3155921660826552801
79
90
  requirements: []
80
91
  rubyforge_project:
81
92
  rubygems_version: 1.8.24
@@ -87,8 +98,14 @@ test_files:
87
98
  - spec/assets/file-1.rb
88
99
  - spec/assets/file-2.rb
89
100
  - spec/assets/file-3.rb
101
+ - spec/assets/file-4
102
+ - spec/assets/file-5
103
+ - spec/assets/file-python
104
+ - spec/assets/file-python.py
105
+ - spec/assets/hello.rb
90
106
  - spec/code2rubylearning/filehandling_spec.rb
91
107
  - spec/code2rubylearning/filter_spec.rb
92
108
  - spec/code2rubylearning/version_spec.rb
93
109
  - spec/code2rubylearning_spec.rb
110
+ - spec/spec_config.rb.example
94
111
  - spec/spec_helper.rb
@@ -1,10 +0,0 @@
1
- # Minitest Reporters Selection
2
- ---
3
- # Your Reporter choices: (They are case sensitive!)
4
- Default
5
- # Spec
6
- # Progress
7
- # Guard
8
- # RubyMine
9
- # RubyMate
10
- ...