Skip to content

Commit

Permalink
Fix Layout/LineLength offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
vsppedro committed Jul 23, 2023
1 parent 65b32f8 commit 5a43719
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
12 changes: 9 additions & 3 deletions exe/convert_to_should_syntax
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ def usage(msg = nil)
puts " ..."
puts " end"
puts
puts "A copy of the old file will be left under #{TMP} in case\nthis script just seriously screws up"
puts "A copy of the old file will be left under #{TMP} in case"
puts "this script just seriously screws up"
puts
exit (msg ? 2 : 0)
end

usage("Wrong number of arguments.") unless ARGV.size == 1
usage("Temp directory '#{TMP}' is not valid. Set TMPDIR environment variable to a writeable directory.") unless File.directory?(TMP) && File.writable?(TMP)

unless File.directory?(TMP) && File.writable?(TMP)
usage("Temp directory '#{TMP}' is not valid. \
Set TMPDIR environment variable to a writeable directory.")
end

file = ARGV.shift
tmpfile = File.join(TMP, File.basename(file))
Expand All @@ -39,4 +44,5 @@ contents.gsub!(/def test_should_(\S+)/) {|line| "should \"#{$1.tr('_', ' ')}\" d
contents.gsub!(/def test_(\S+)/) {|line| "should \"RENAME ME: test #{$1.tr('_', ' ')}\" do"}
File.open(file, 'w') { |f| f.write(contents) }

puts "File '#{file}' has been converted to 'should' syntax. Old version has been stored in '#{tmpfile}'"
puts "File '#{file}' has been converted to 'should' syntax. \
Old version has been stored in '#{tmpfile}'"
5 changes: 4 additions & 1 deletion lib/shoulda/context/assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ module Assertions
# assert_same_elements([:a, :b, :c], [:c, :a, :b]) => passes)
def assert_same_elements(a1, a2, msg = nil)
[:select, :inject, :size].each do |m|
[a1, a2].each {|a| assert_respond_to(a, m, "Are you sure that #{a.inspect} is an array? It doesn't respond to #{m}.") }
[a1, a2].each do |a|
assert_respond_to(a, m,
"Are you sure that #{a.inspect} is an array? It doesn't respond to #{m}.",)
end
end

assert a1h = a1.inject({}) { |h,e| h[e] ||= a1.select { |i| i == e }.size; h }
Expand Down
3 changes: 2 additions & 1 deletion lib/shoulda/context/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class Context # :nodoc:
attr_accessor :setup_blocks # blocks given via setup methods
attr_accessor :teardown_blocks # blocks given via teardown methods
attr_accessor :shoulds # array of hashes representing the should statements
# rubocop:disable Layout/LineLength
attr_accessor :should_eventuallys # array of hashes representing the should eventually statements
# rubocop:enable Layout/LineLength

# accessor with cache
def subject_block
Expand Down Expand Up @@ -213,4 +215,3 @@ def method_missing(method, *args, &blk)
class DuplicateTestError < RuntimeError; end
end
end

12 changes: 10 additions & 2 deletions test/shoulda/context_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def self.context_macro(&blk)
end

should "be named correctly" do
assert_match(/^test: context with setup block and a subcontext should be named correctly/, normalized_name)
assert_match(/^test: context with setup block and a subcontext should be named correctly/,
normalized_name)
end

should "run the setup blocks in order" do
Expand All @@ -37,9 +38,14 @@ def self.context_macro(&blk)
end

context_macro do
# rubocop:disable Layout/LineLength
should "have name set right" do
assert_match(/^test: context with setup block with a subcontext made by a macro should have name set right/, normalized_name)
assert_match(
/^test: context with setup block with a subcontext made by a macro should have name set right/,
normalized_name
)
end
# rubocop:enable Layout/LineLength

should "run the setup block of that context macro" do
assert_equal :foo, @context_macro
Expand Down Expand Up @@ -108,11 +114,13 @@ def hello; "hi"; end
teardown { cleanup_count -= 1 }
end

# rubocop:disable Layout/LineLength
2.times do |i|
should "also call all setups and all teardowns in parent and subcontext (check ##{i + 1})" do
assert_equal 4, cleanup_count
end
end
# rubocop:enable Layout/LineLength

end

Expand Down
3 changes: 2 additions & 1 deletion test/shoulda/convert_to_should_syntax_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def non_test_method

def test_convert_to_should_syntax
File.open(FIXTURE_PATH, "w") {|f| f.write(BEFORE_FIXTURE)}
cmd = "#{RUBY} #{File.join(File.dirname(__FILE__), '../../exe/convert_to_should_syntax')} #{FIXTURE_PATH}"
cmd = "#{RUBY} #{File.join(File.dirname(__FILE__),
'../../exe/convert_to_should_syntax',)} #{FIXTURE_PATH}"
output = `#{cmd}`
File.unlink($1) if output.match(/has been stored in '([^']+)/)
assert_match(/has been converted/, output)
Expand Down

0 comments on commit 5a43719

Please sign in to comment.