Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialruby gupta
1,200 PointsDuplicateTestError: 'test_: #edit when logged in should assign a user_friendship. ' is defined more than once.
When i run "rake test" i get error of "DuplicateTestError" i dont know how to solve it.
$ rake test
DL is deprecated, please use Fiddle
rake aborted!
DuplicateTestError: 'test_: #edit when logged in should assign a user_friendship. ' is defined more than once.
C:/Users/Arvind/project/book/test/controllers/user_friendships_controller_test.rb:285:in <class:UserFriendshipsControllerTest>'
C:/Users/Arvind/project/book/test/controllers/user_friendships_controller_test.rb:3:in
<top (required)>'
Tasks: TOP => test:run
(See full trace by running task with --trace)
When i try to run "ruby -Itest test/controllers/user_friendships_controller_test.rb" i get this error:-
$ ruby -Itest test/controllers/user_friendships_controller_test.rb
DL is deprecated, please use Fiddle
c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/shoulda-context-1.2.1/lib/shoulda/context/context.rb:393:in create_test_from_should_hash': '
test_: #edit when logged in should assign a user_friendship. ' is defined more than once. (DuplicateTestError)
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/shoulda-context-1.2.1/lib/shoulda/context/context.rb:465:in
block in build'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/shoulda-context-1.2.1/lib/shoulda/context/context.rb:464:in each'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/shoulda-context-1.2.1/lib/shoulda/context/context.rb:464:in
build'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/shoulda-context-1.2.1/lib/shoulda/context/context.rb:468:in block in build'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/shoulda-context-1.2.1/lib/shoulda/context/context.rb:468:in
each'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/shoulda-context-1.2.1/lib/shoulda/context/context.rb:468:in build'
from c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/shoulda-context-1.2.1/lib/shoulda/context/context.rb:201:in
context'
from test/controllers/user_friendships_controller_test.rb:285:in <class:UserFriendshipsControllerTest>'
from test/controllers/user_friendships_controller_test.rb:3:in
<main>'
This is my code for user_friendships_controller_test.rb:-
context "#edit" do
context "when not logged in" do
should "redirected to the login page" do
get :edit, id: 1
assert_response :redirect
end
end
context "when logged in" do
setup do
@user_friendship = create(:pending_user_friendship, user: users(:sarah))
sign_in users(:sarah)
get :edit, id: @user_friendship.friend.profile_name
end
should "get a edit and return success" do
assert_response :success
end
should "assign a user_friendship" do
assert assigns(:user_friendship)
end
should "assign a user_friendship" do
assert assigns(:friend)
end
Thanks!!!!
1 Answer
Maciej Czuchnowski
36,441 PointsHere:
should "assign a user_friendship" do
assert assigns(:user_friendship)
end
should "assign a user_friendship" do
assert assigns(:friend)
end
You have exactly the same name for both tests. Just change one of them a bit.
ruby gupta
1,200 Pointsruby gupta
1,200 PointsThanks it work!!!!!
Code is:-
should "assign a user_friendship" do