Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix tests, fix a bug in multiline strings, and additional minor cleanup #1

Open
wants to merge 7 commits into from
This page is out of date. Refresh to see the latest.
1  .gitignore
View
@@ -1 +1,2 @@
Gemfile.lock
+/pkg
9 README.md
View
@@ -27,10 +27,11 @@ It has help:
## Contributing
1. Fork it
-2. Create your feature branch (`git checkout -b my-new-feature`)
-3. Commit your changes (`git commit -am 'Added some feature'`)
-4. Push to the branch (`git push origin my-new-feature`)
-5. Create new Pull Request
+1. Create your feature branch (`git checkout -b my-new-feature`)
+1. Commit your changes (`git commit -am 'Added some feature'`)
+1. run tests (`rake`)
+1. Push to the branch (`git push origin my-new-feature`)
+1. Create new Pull Request
# History
8 Rakefile
View
@@ -1,2 +1,6 @@
-#!/usr/bin/env rake
-require "bundler/gem_tasks"
+require 'bundler/gem_tasks'
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new(:spec)
+
+task :default => :spec
2  lib/beautifier.rb
View
@@ -1,5 +1,3 @@
-#!/usr/bin/env ruby
-
# Ruby beautifier, version 2.1, 09/11/2006
# Copyright (c) 2006, P. Lutus
# Released under the GPL
2  lib/ruby-beautify/line.rb
View
@@ -20,7 +20,7 @@ def format
@formatted = tab_string + stripped
end
else
- @formatted = content
+ @formatted = content.sub(/\n$/, '')
end
end
12 spec/rbeautify/block_matcher_spec.rb
View
@@ -68,22 +68,22 @@
describe '#can_nest?' do
before(:each) do
- @language = mock(RBeautify::Language)
+ @language = double(RBeautify::Language)
end
it { RBeautify::BlockMatcher.new(@language, :foo, /foo/, /bar/).should be_can_nest(nil) }
- it { RBeautify::BlockMatcher.new(@language, :foo, /foo/, /bar/).should be_can_nest(mock('block_start', :parse_content? => true)) }
+ it { RBeautify::BlockMatcher.new(@language, :foo, /foo/, /bar/).should be_can_nest(double('block_start', :parse_content? => true)) }
- it { RBeautify::BlockMatcher.new(@language, :foo, /foo/, /bar/).should_not be_can_nest(mock('block_start', :parse_content? => false)) }
+ it { RBeautify::BlockMatcher.new(@language, :foo, /foo/, /bar/).should_not be_can_nest(double('block_start', :parse_content? => false)) }
it { RBeautify::BlockMatcher.new(@language, :foo, /foo/, /bar/, :nest_except => [:bar]).should be_can_nest(nil) }
- it { RBeautify::BlockMatcher.new(@language, :foo, /foo/, /bar/, :nest_except => [:foo]).should be_can_nest(mock('block_start', :name => :bar, :parse_content? => true)) }
+ it { RBeautify::BlockMatcher.new(@language, :foo, /foo/, /bar/, :nest_except => [:foo]).should be_can_nest(double('block_start', :name => :bar, :parse_content? => true)) }
- it { RBeautify::BlockMatcher.new(@language, :foo, /foo/, /bar/, :nest_except => [:foo]).should_not be_can_nest(mock('block_start', :name => :bar, :parse_content? => false)) }
+ it { RBeautify::BlockMatcher.new(@language, :foo, /foo/, /bar/, :nest_except => [:foo]).should_not be_can_nest(double('block_start', :name => :bar, :parse_content? => false)) }
- it { RBeautify::BlockMatcher.new(@language, :foo, /foo/, /bar/, :nest_except => [:bar]).should_not be_can_nest(mock('block_start', :name => :bar, :parse_content? => true)) }
+ it { RBeautify::BlockMatcher.new(@language, :foo, /foo/, /bar/, :nest_except => [:bar]).should_not be_can_nest(double('block_start', :name => :bar, :parse_content? => true)) }
end
end
2  spec/rbeautify/block_start_spec.rb
View
@@ -43,7 +43,7 @@
it { RBeautify::BlockStart.new(@ruby.matcher(:standard), nil, 0, 0, 'def', ' foo') .total_indent_size.should == 2 }
it 'should sum with parents total indent size' do
- parent = mock('parent_start_block', :total_indent_size => 4)
+ parent = double('parent_start_block', :total_indent_size => 4)
RBeautify::BlockStart.new(@ruby.matcher(:standard), parent, 0, 0, 'def', ' foo') .total_indent_size.should == 6
end
end
40 spec/rbeautify/line_spec.rb
View
@@ -5,66 +5,66 @@
describe '#format' do
before(:each) do
- @language = mock(RBeautify::Language)
+ @language = double(RBeautify::Language)
end
it 'should just strip with empty stack' do
- RBeautify::BlockMatcher.stub!(:parse => nil)
+ RBeautify::BlockMatcher.stub(:parse => nil)
RBeautify::Line.new(@language, ' a = 3 ', 0).format.should == "a = 3"
end
it 'should indent with existing indent' do
- current_block = mock('block_start', :total_indent_size => 2, :format_content? => true, :strict_ancestor_of? => false)
+ current_block = double('block_start', :total_indent_size => 2, :format_content? => true, :strict_ancestor_of? => false)
RBeautify::BlockStart.stub(:first_common_ancestor => current_block)
- RBeautify::BlockMatcher.stub!(:parse => current_block)
+ RBeautify::BlockMatcher.stub(:parse => current_block)
RBeautify::Line.new(@language, ' a = 3 ', 0, current_block).format.should == ' a = 3'
end
it 'leave empty lines blank' do
- current_block = mock('block_start', :format_content? => true)
- RBeautify::BlockMatcher.stub!(:parse => current_block)
+ current_block = double('block_start', :format_content? => true)
+ RBeautify::BlockMatcher.stub(:parse => current_block)
RBeautify::Line.new(@language, ' ', 0, current_block).format.should == ''
end
it 'should remove indent with match to end of block' do
- current_block = mock('block_start', :format_content? => true, :indent_end_line? => false)
+ current_block = double('block_start', :format_content? => true, :indent_end_line? => false)
RBeautify::BlockStart.stub(:first_common_ancestor => nil)
- RBeautify::BlockMatcher.stub!(:parse => nil)
+ RBeautify::BlockMatcher.stub(:parse => nil)
RBeautify::Line.new(@language, ' end ', 0, current_block).format.should == 'end'
end
it 'should not remove indent with match to end of block if indent_end_line? is true' do
- current_block = mock('block_start', :total_indent_size => 2, :format_content? => true, :indent_end_line? => true)
- RBeautify::BlockMatcher.stub!(:parse => nil)
+ current_block = double('block_start', :total_indent_size => 2, :format_content? => true, :indent_end_line? => true)
+ RBeautify::BlockMatcher.stub(:parse => nil)
RBeautify::Line.new(@language, ' end ', 0, current_block).format.should == ' end'
end
it 'should leave indent at old stack level with match of new block' do
- current_block = mock('current_block_start', :total_indent_size => 2, :format_content? => true)
- new_block = mock('new_block_start', :format_content? => true, :strict_ancestor_of? => false)
+ current_block = double('current_block_start', :total_indent_size => 2, :format_content? => true)
+ new_block = double('new_block_start', :format_content? => true, :strict_ancestor_of? => false)
RBeautify::BlockStart.stub(:first_common_ancestor => current_block)
- RBeautify::BlockMatcher.stub!(:parse => new_block)
+ RBeautify::BlockMatcher.stub(:parse => new_block)
RBeautify::Line.new(@language, 'class Foo', 0, current_block).format.should == ' class Foo'
end
it 'should remove indent if a block ends and starts' do
- current_block = mock('current_block_start', :format_content? => true)
- new_block = mock('new_block_start', :format_content? => true, :strict_ancestor_of? => false)
+ current_block = double('current_block_start', :format_content? => true)
+ new_block = double('new_block_start', :format_content? => true, :strict_ancestor_of? => false)
RBeautify::BlockStart.stub(:first_common_ancestor => nil)
- RBeautify::BlockMatcher.stub!(:parse => new_block)
+ RBeautify::BlockMatcher.stub(:parse => new_block)
RBeautify::Line.new(@language, ' else ', 0, current_block).format.should == 'else'
end
it 'should not change when format is false' do
- current_block = mock('block_start', :format_content? => false)
- RBeautify::BlockMatcher.stub!(:parse => current_block)
+ current_block = double('block_start', :format_content? => false)
+ RBeautify::BlockMatcher.stub(:parse => current_block)
RBeautify::Line.new(@language, ' some content after program has finished. ', 0, current_block).format.should ==
" some content after program has finished. "
end
it 'should leave indent with match to end of block (but no format)' do
- current_block = mock('block_start', :format_content? => false)
- RBeautify::BlockMatcher.stub!(:parse => nil)
+ current_block = double('block_start', :format_content? => false)
+ RBeautify::BlockMatcher.stub(:parse => nil)
RBeautify::Line.new(@language, ' "', 0, current_block).format.should == ' "'
end
Something went wrong with that request. Please try again.