nesterukD@gmail.com
2010-Sep-15 09:36 UTC
[rspec-users] Rspec and rails: Problems while testing libraries in the lib directory
I have some classes in the lib directory, and I want to test it. My
class which I want to test looks like:
class StatAggregation
class << self
def skills_rate(user_id)
user_id = User.find_by_id(user_id)
...
end
end
end
I created spec:
require File.expand_path(File.dirname(__FILE__) + ''/../../
spec_helper'')
describe StatAggregation do
fixtures [
:users
]
describe ''skills_rate method'' do
it ''should work'' do
@user_id = 1
@user = mock_model(User)
User.should_receive(:find_by_id).with(@user_id).and_return(@user)
...
StatAggregation.skills_rate(@user_id)
end
end
end
It works ok, but it doesn''t show where appeared error:
1)
ArgumentError in ''PxStatAggregation skills_rate method should
work''
wrong number of arguments (1 for 0)
script/spec:10:
Finished in 0.326331 seconds
How to get number of line where appeared error "wrong number of
arguments (1 for 0)"?
David Chelimsky
2010-Sep-15 13:20 UTC
[rspec-users] Rspec and rails: Problems while testing libraries in the lib directory
On Wed, Sep 15, 2010 at 4:36 AM, nesterukD at gmail.com <nesterukd at gmail.com> wrote:> I have some classes in the lib directory, and I want to test it. My > class which I want to test looks like: > > class StatAggregation > ?class << self > ? ?def skills_rate(user_id) > ? ? ?user_id = User.find_by_id(user_id) > ? ? ?... > ? ?end > ?end > end > > I created spec: > > require File.expand_path(File.dirname(__FILE__) + ''/../../ > spec_helper'') > > describe StatAggregation do > ?fixtures [ > ? ?:users > ?] > > ?describe ''skills_rate method'' do > ? ?it ''should work'' do > ? ? ?@user_id = 1 > ? ? ?@user = mock_model(User) > > User.should_receive(:find_by_id).with(@user_id).and_return(@user) > ? ? ?... > ? ? ?StatAggregation.skills_rate(@user_id) > ? ?end > ?end > end > > It works ok, but it doesn''t show where appeared error: > > 1) > ArgumentError in ''PxStatAggregation skills_rate method should work'' > wrong number of arguments (1 for 0) > script/spec:10: > > Finished in 0.326331 seconds > > How to get number of line where appeared error "wrong number of > arguments (1 for 0)"?Use the -h flag on the [r]spec command (rspec for rspec-2, spec for rspec-1) to learn about the command line options: # rspec-1 spec -h # rspec-2 rspec -h In either case you''ll see a -b flag to get a full backtrace: # rspec-1 spec spec -b # rspec-2 rspec spec -b HTH, David