Skip to content

Commit

Permalink
RSpec 3 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
makaroni4 committed May 12, 2015
1 parent 1751ea8 commit 17f42b3
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 75 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ gemspec

group :test do
gem 'rspec'
gem 'pry' # standard debugger
gem 'fakefs', require: 'fakefs/safe' # stubs out FS to avoid creating files during testing
gem 'pry'
gem 'fakefs', require: 'fakefs/safe'
end
70 changes: 35 additions & 35 deletions spec/analyzer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
it 'finds indentation warnings for method' do
klass = analyzer.classes.find { |c| c.name == "TestClass" }

klass.should have_attributes(
expect(klass).to have_attributes(
first_line: 1,
last_line: 5,
path: test_file_path(3)
Expand All @@ -24,7 +24,7 @@
it 'finds methods' do
method = analyzer.methods["TestClass"].find { |m| m.name == "blah" }

method.should have_attributes(
expect(method).to have_attributes(
first_line: 2,
last_line: 4,
number_of_arguments: 0,
Expand All @@ -35,7 +35,7 @@
it 'finds method calls that brakes third rule' do
method_call = analyzer.method_calls.first

method_call.should have_attributes(
expect(method_call).to have_attributes(
first_line: 3,
number_of_arguments: 5,
path: test_file_path(3)
Expand All @@ -53,7 +53,7 @@
it 'finds indentation warnings for method' do
klass = analyzer.classes.find { |c| c.name == "MyApp::TestClass" }

klass.should have_attributes(
expect(klass).to have_attributes(
first_line: 2,
last_line: nil,
path: test_file_path(1)
Expand All @@ -63,7 +63,7 @@
it 'finds methods' do
method = analyzer.methods["MyApp::TestClass"].find { |m| m.name == "blah" }

method.should have_attributes(
expect(method).to have_attributes(
first_line: 3,
last_line: nil,
number_of_arguments: 0,
Expand All @@ -82,15 +82,15 @@
it 'finds classes' do
klass = analyzer.classes.find { |c| c.name == "FirstTestClass" }

klass.should have_attributes(
expect(klass).to have_attributes(
first_line: 1,
last_line: 4,
path: test_file_path(4)
)

klass = analyzer.classes.find { |c| c.name == "SecondTestClass" }

klass.should have_attributes(
expect(klass).to have_attributes(
first_line: 6,
last_line: 9,
path: test_file_path(4)
Expand All @@ -100,7 +100,7 @@
it 'finds methods' do
method = analyzer.methods["FirstTestClass"].find { |m| m.name == "first_meth" }

method.should have_attributes(
expect(method).to have_attributes(
first_line: 2,
last_line: 3,
number_of_arguments: 1,
Expand All @@ -109,7 +109,7 @@

method = analyzer.methods["SecondTestClass"].find { |m| m.name == "second_meth" }

method.should have_attributes(
expect(method).to have_attributes(
first_line: 7,
last_line: 8,
number_of_arguments: 1,
Expand All @@ -128,15 +128,15 @@
it 'finds classes' do
klass = analyzer.classes.find { |c| c.name == "OneLinerClass" }

klass.should have_attributes(
expect(klass).to have_attributes(
first_line: 1,
last_line: nil,
path: test_file_path(5)
)
end

it 'finds methods' do
analyzer.methods.should be_empty
expect(analyzer.methods).to be_empty
end
end

Expand All @@ -149,14 +149,14 @@

it 'finds class and subclass' do
klass = analyzer.classes.find { |c| c.name == "MyApp::Blah::User" }
klass.should have_attributes(
expect(klass).to have_attributes(
first_line: 5,
last_line: 13,
path: test_file_path(7)
)

klass = analyzer.classes.find { |c| c.name == "MyApp::Blah::User::SubUser" }
klass.should have_attributes(
expect(klass).to have_attributes(
first_line: 9,
last_line: 12,
path: test_file_path(7)
Expand All @@ -165,23 +165,23 @@

it 'finds methods' do
method = analyzer.methods["MyApp::Blah"].find { |m| m.name == "module_meth" }
method.should have_attributes(
expect(method).to have_attributes(
first_line: 2,
last_line: 3,
number_of_arguments: 0,
path: test_file_path(7)
)

method = analyzer.methods["MyApp::Blah::User"].find { |m| m.name == "class_meth" }
method.should have_attributes(
expect(method).to have_attributes(
first_line: 6,
last_line: 7,
number_of_arguments: 0,
path: test_file_path(7)
)

method = analyzer.methods["MyApp::Blah::User::SubUser"].find { |m| m.name == "sub_meth" }
method.should have_attributes(
expect(method).to have_attributes(
first_line: 10,
last_line: 11,
number_of_arguments: 0,
Expand All @@ -199,7 +199,7 @@

it 'finds class and subclass' do
klass = analyzer.classes.find { |c| c.name == "RailsController" }
klass.should have_attributes(
expect(klass).to have_attributes(
first_line: 1,
last_line: 12,
path: test_file_path(8)
Expand All @@ -208,23 +208,23 @@

it 'finds methods' do
method = analyzer.methods["RailsController"].find { |m| m.name == "index" }
method.should have_attributes(
expect(method).to have_attributes(
first_line: 2,
last_line: 3,
number_of_arguments: 0,
path: test_file_path(8)
)

method = analyzer.methods["RailsController"].find { |m| m.name == "destroy" }
method.should have_attributes(
expect(method).to have_attributes(
first_line: 5,
last_line: 6,
number_of_arguments: 0,
path: test_file_path(8)
)

method = analyzer.methods["RailsController"].find { |m| m.name == "private_meth" }
method.should be_nil
expect(method).to be_nil
end
end

Expand All @@ -238,7 +238,7 @@

it 'finds instance variable' do
method = analyzer.methods["UsersController"].find { |m| m.name == "index" }
method.ivars.should eq(["@users"])
expect(method.ivars).to eq(["@users"])
end
end

Expand All @@ -251,7 +251,7 @@

it 'does not find instance variables' do
method = analyzer.methods["GuestController"].find { |m| m.name == "create_guest_user" }
method.ivars.should be_empty
expect(method.ivars).to be_empty
end
end

Expand All @@ -264,10 +264,10 @@

it 'does not find instance variable' do
method = analyzer.methods["User"].find { |m| m.name == "initialize" }
method.ivars.should be_empty
expect(method.ivars).to be_empty

method = analyzer.methods["User"].find { |m| m.name == "hi" }
method.ivars.should be_empty
expect(method.ivars).to be_empty
end
end

Expand All @@ -280,22 +280,22 @@

it 'finds method defined after public keyword' do
method = analyzer.methods["UsersController"].find { |m| m.name == "create" }
method.ivars.should eq(["@user"])
expect(method.ivars).to eq(["@user"])
end

it 'omits actions without instance variables' do
method = analyzer.methods["UsersController"].find { |m| m.name == "show" }
method.ivars.should be_empty
expect(method.ivars).to be_empty
end

it 'omits private methods' do
method = analyzer.methods["UsersController"].find { |m| m.name == "find_user" }
method.should be_nil
expect(method).to be_nil
end

it 'omits protected methods' do
method = analyzer.methods["UsersController"].find { |m| m.name == "protected_find_user" }
method.should be_nil
expect(method).to be_nil
end
end
end
Expand All @@ -310,7 +310,7 @@
it 'counts arguments' do
method_call = analyzer.method_calls.first

method_call.should have_attributes(
expect(method_call).to have_attributes(
first_line: 3,
number_of_arguments: 5,
path: test_file_path(11)
Expand All @@ -328,7 +328,7 @@
it 'are count for class definition' do
klass = analyzer.classes.find { |c| c.name == "Valera" }

klass.should have_attributes(
expect(klass).to have_attributes(
first_line: 1,
last_line: 109,
path: test_file_path(12)
Expand All @@ -338,7 +338,7 @@
it 'are count for method definition' do
method = analyzer.methods["Valera"].find { |m| m.name == "doodle" }

method.should have_attributes(
expect(method).to have_attributes(
first_line: 2,
last_line: 9,
number_of_arguments: 0,
Expand All @@ -355,7 +355,7 @@
end

it 'is not scanned' do
analyzer.method_calls.should be_empty
expect(analyzer.method_calls).to be_empty
end
end

Expand All @@ -370,7 +370,7 @@
it 'mark 4line methods good' do
method = analyzer.methods["TestClass"].find { |m| m.name == "render4" }

method.should have_attributes(
expect(method).to have_attributes(
first_line: 2,
last_line: 7,
number_of_arguments: 0,
Expand All @@ -381,7 +381,7 @@
it 'mark 5line methods good' do
method = analyzer.methods["TestClass"].find { |m| m.name == "render5" }

method.should have_attributes(
expect(method).to have_attributes(
first_line: 9,
last_line: 15,
number_of_arguments: 0,
Expand All @@ -392,7 +392,7 @@
it 'mark 6line methods bad' do
method = analyzer.methods["TestClass"].find { |m| m.name == "render6" }

method.should have_attributes(
expect(method).to have_attributes(
first_line: 17,
last_line: 24,
number_of_arguments: 0,
Expand Down
8 changes: 4 additions & 4 deletions spec/calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
it 'counts class lines' do
output = calculator.calculate!(true)
klass = output[:first_rule][:log][:classes].find { |params| params.first == "User" }
klass[1].should eq(109)
expect(klass[1]).to eq(109)
end

it 'counts method lines' do
output = calculator.calculate!(true)
method_params = output[:second_rule][:log][:methods].find { |method| method[1] == "create" }
method_params[2].should eq(6)
expect(method_params[2]).to eq(6)
end
end

Expand Down Expand Up @@ -69,12 +69,12 @@
describe 'no matching ruby files found' do
it 'counts class lines' do
output = calculator.calculate!(false)
output[:first_rule][:total_classes_amount].should eql(0)
expect(output[:first_rule][:total_classes_amount]).to eql(0)
end

it 'counts method lines' do
output = calculator.calculate!(true)
output[:second_rule][:total_methods_amount].should eql(0)
expect(output[:second_rule][:total_methods_amount]).to eq(0)
end
end
end
Loading

2 comments on commit 17f42b3

@dkarter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@makaroni4
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄

Please sign in to comment.