my tests are running with no errors..
but how do i check whether the functional tests i wrote are working..i
need please..
require File.dirname(__FILE__) + ''/../test_helper''
class BooksControllerTest < ActionController::TestCase
def setup
@controller = BooksController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
login_as :sanj
end
fixtures :books
def test_should_get_index
login_as(:sanj)
get :index
assert_response :found
assert_nil assigns(:book)
end
def test_should_get_new
login_as(:sanj)
get :new
assert_response :found
end
def test_should_update_book_name
login_as(:sanj)
assert_difference(''Book.count'',0) do
post :update, :book => {:name => "shkj"}
end
end
def test_should_get_details
login_as(:sanj)
assert_difference(''Book.count'',0) do
get :book =>{}
end
end
def test_should_update_num_of_books
login_as(:sanj)
assert_difference(''Book.count'',0) do
post :update, :book => {:num_books => 7}
end
end
def test_should_update_book_buyin
login_as(:sanj)
assert_difference(''Book.count'',0) do
post :update, :book => {:buyin => 20}
end
end
def test_should_update_book_book_fee
login_as(:sanj)
assert_difference(''Book.count'',0) do
post :update, :book => {:book_fee => 1200}
end
end
def test_should_create_book
login_as(:sanj)
assert_difference(''Book.count'',0) do
post :create, :book => {:name => "ssss",:num_books =>
5,:buyin
=>
1000,:book_fee => 1500}
end
end
def test_should_edit_book_name
login_as(:sanj)
assert_difference(''Book.count'',0) do
post :edit, :book => {:name => "sshh"}
end
end
def test_should_update_book_details
login_as(:sanj)
assert_difference(''Book.count'',0) do
post :update, :book => {:name => "sshf",:num_books => 10,
:buyin
=>3000,
:book_fee => 4000}
end
end
def test_should_edit_no_of_books
login_as(:sanj)
assert_difference(''Book.count'',0) do
post :edit, :book => {:num_books => "6"}
end
end
def test_should_edit_the_book_details
login_as(:sanj)
assert_difference(''Book.count'',0) do
post :edit, :book => {:name => "sssss",:num_books => 5,
:buyin =>2000,
:book_fee => 2000}
end
end
def test_should_edit_book_fee
login_as(:sanj)
assert_difference(''Book.count'',0) do
post :edit, :book => {:book_fee => "1600"}
end
end
def test_should_edit_book_buying
login_as(:sanj)
assert_difference(''Book.count'',0) do
post :edit, :book => {:buyin => "1200"}
end
end
def test_should_show_book
login_as(:sanj)
get :show, :id => 1
assert_response :found
end
def test_should_edit_book
login_as(:sanj)
get :edit, :id => 1
assert_response :found
end
def test_should_update_the_book_name
login_as(:sanj)
put :update, :id => 2, :book => {}
end
def test_should_update_book
login_as(:sanj)
put :update, :id => 1, :book => { }
end
def test_should_destroy_book
login_as(:sanj)
assert_difference(''Book.count'',0) do
delete :destroy, :id => 1, :admins_id => admins(:sanj).id
end
end
end
is this correct functional tests???..how do i check whether the tests
i
wrote are correct??..
they are executing without errors...
Loaded suite test/functional/books_controller_test
Started
........................
Finished in 0.379324 seconds.
24 tests, 25 assertions, 0 failures, 0 errors
but how do i check whether they are correct tests??..i need helppp
pleaseee
thank you
Reply with quote
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
It looks like the tests are passing, but maybe you should be a little more specific in your tests. You mainly check that the nbr of records are increased and that you get a successful response. I would test that the correct view gets rendered, maybe that the assign variables in the controller really is the book-record(s) you are assuming, and that the updated records really set the values that send as parameters. How much you would test also depends on what our kind of test suites you have. If you have tests at a higher level (like selenium) maybe you could remove some the tests in functional tests. If you dont trust your test-suite, you are not testing enough :) Good luck, Kristian Hellquist 2009/12/5 sanjanad <d_sanjana7-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>:> > > my tests are running with no errors.. > > but how do i check whether the functional tests i wrote are working..i > need please.. > > require File.dirname(__FILE__) + ''/../test_helper'' > > class BooksControllerTest < ActionController::TestCase > > def setup > @controller = BooksController.new > @request = ActionController::TestRequest.new > @response = ActionController::TestResponse.new > login_as :sanj > end > > fixtures :books > > def test_should_get_index > login_as(:sanj) > get :index > assert_response :found > assert_nil assigns(:book) > end > > def test_should_get_new > login_as(:sanj) > get :new > assert_response :found > end > > def test_should_update_book_name > login_as(:sanj) > assert_difference(''Book.count'',0) do > post :update, :book => {:name => "shkj"} > end > end > > def test_should_get_details > login_as(:sanj) > assert_difference(''Book.count'',0) do > get :book =>{} > end > end > > def test_should_update_num_of_books > login_as(:sanj) > assert_difference(''Book.count'',0) do > post :update, :book => {:num_books => 7} > end > end > > def test_should_update_book_buyin > login_as(:sanj) > assert_difference(''Book.count'',0) do > post :update, :book => {:buyin => 20} > end > end > > def test_should_update_book_book_fee > login_as(:sanj) > assert_difference(''Book.count'',0) do > post :update, :book => {:book_fee => 1200} > end > end > > def test_should_create_book > login_as(:sanj) > assert_difference(''Book.count'',0) do > post :create, :book => {:name => "ssss",:num_books => 5,:buyin > => > 1000,:book_fee => 1500} > end > end > > def test_should_edit_book_name > login_as(:sanj) > assert_difference(''Book.count'',0) do > post :edit, :book => {:name => "sshh"} > end > end > > def test_should_update_book_details > login_as(:sanj) > assert_difference(''Book.count'',0) do > post :update, :book => {:name => "sshf",:num_books => 10, :buyin > =>3000, > :book_fee => 4000} > end > end > > def test_should_edit_no_of_books > login_as(:sanj) > assert_difference(''Book.count'',0) do > post :edit, :book => {:num_books => "6"} > end > end > > def test_should_edit_the_book_details > login_as(:sanj) > assert_difference(''Book.count'',0) do > post :edit, :book => {:name => "sssss",:num_books => 5, :buyin =>2000, > :book_fee => 2000} > end > end > > def test_should_edit_book_fee > login_as(:sanj) > assert_difference(''Book.count'',0) do > post :edit, :book => {:book_fee => "1600"} > end > end > > def test_should_edit_book_buying > login_as(:sanj) > assert_difference(''Book.count'',0) do > post :edit, :book => {:buyin => "1200"} > end > end > > def test_should_show_book > login_as(:sanj) > get :show, :id => 1 > assert_response :found > end > > def test_should_edit_book > login_as(:sanj) > get :edit, :id => 1 > assert_response :found > end > > def test_should_update_the_book_name > login_as(:sanj) > put :update, :id => 2, :book => {} > end > > def test_should_update_book > login_as(:sanj) > put :update, :id => 1, :book => { } > end > > def test_should_destroy_book > login_as(:sanj) > assert_difference(''Book.count'',0) do > delete :destroy, :id => 1, :admins_id => admins(:sanj).id > end > end > end > > is this correct functional tests???..how do i check whether the tests > i > wrote are correct??.. > > they are executing without errors... > > Loaded suite test/functional/books_controller_test > Started > ........................ > Finished in 0.379324 seconds. > > 24 tests, 25 assertions, 0 failures, 0 errors > > but how do i check whether they are correct tests??..i need helppp > pleaseee > > thank you > > Reply with quote > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2009/12/5 sanjanad <d_sanjana7-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>:> > > my tests are running with no errors.. > > but how do i check whether the functional tests i wrote are working..i > need please..For each test slightly change the code in your app (not the test) so that the test will fail, then check that it does fail. For example to check an update test, comment out the code that saves the update to the database, the update test should then fail. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Dec 5, 10:27 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/12/5 sanjanad <d_sanja...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>: > > my tests are running with no errors.. > > > but how do i check whether the functional tests i wrote are working..i > > need please.. > > For each test slightly change the code in your app (not the test) so > that the test will fail, then check that it does fail. For example to > check an update test, comment out the code that saves the update to > the database, the update test should then fail. >Maybe not helpful now, given that you''ve already got all this code but next time try writing the test first. It should fail since you haven''t written the code that performs the task. Write the code and check that the test now passes. Everytime you want to make a change write a new test (or change an existing one if appropriate), check that it fails and then write the code. Do this in small steps. Fred> Colin-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> require File.dirname(__FILE__) + ''/../test_helper''class BooksControllerTest < ActionController::TestCase def setup @controller = BooksController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new login_as :sanj end fixtures :books def test_should_get_index login_as(:sanj) get :index assert_response :found assert_nil assigns(:book) end def test_should_get_new login_as(:sanj) get :new assert_response :found end def test_should_update_book_name login_as(:sanj) assert_difference(''Book.count'',0) do post :update, :book => {:name => "shkj"} end end i guess i m assuming that i m updating the name to shjk... but where do i check that..??? i m totallyy lost and coming up with weird doubts but thank u all for replyin..i shall look into ur suggestions thank u -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> def test_should_update_book_name > login_as(:sanj) > assert_difference(''Book.count'',0) do > post :update, :book => {:name => "shkj"} > end > end > > i guess i m assuming that i m updating the name to shjk... > > but where do i check that..??? > > i m totallyy lost and coming up with weird doubts > > but thank u all for replyin..i shall look into ur suggestionsWell typically you''d fetch that row from the database to check that the book''s name had actually changed (that test looks wrong though - you''re not telling your controller which row to update) Fred> > thank u-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Dec 8, 1:00 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > def test_should_update_book_name > > login_as(:sanj) > > assert_difference(''Book.count'',0) do > > post :update, :book => {:name => "shkj"} > > end > > end > > > i guess i m assuming that i m updating the name to shjk... > > > but where do i check that..??? > > > i m totallyy lost and coming up with weird doubts > > > but thank u all for replyin..i shall look into ur suggestions > > Well typically you''d fetch that row from the database to check that > the book''s name had actually changed (that test looks wrong though - > you''re not telling your controller which row to update) > > Fred > >hi.. to fetch tat row..the command i gave is Book.find(1) in the script/console test but it reads the data from the fixtures and just displays that... how do i tell the controller which row to update..and how do i check that particular row whether its updated?..thank you -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Dec 8, 6:45 pm, sanjanad <d_sanja...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> > to fetch tat row..the command i gave is Book.find(1) > > in the script/console test > > but it reads the data from the fixtures and just displays that... > > how do i tell the controller which row to update..and how do i checkthat depends on your controller. What parameters does it expect?> that particular row whether its updated?..thank youwell in your test reload the book object and check its attributes. Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2009/12/8 sanjanad <d_sanjana7-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>:>... > to fetch tat row..the command i gave is Book.find(1) > > in the script/console test > > but it reads the data from the fixtures and just displays that... > > how do i tell the controller which row to update..and how do i check > that particular row whether its updated?..thank you >If you have not already done so I would suggest working through the rails guide Getting Started and also the one on Testing. See http://guides.rubyonrails.org/. If you make sure that you understand everything in these two guides then you should have the answers to your questions. The guides on ActiveRecord Associations and Debugging are also compulsory reading. If there is something there that you cannot understand then ask here. I am sure you will find that approach much more useful than asking here for every problem you encounter. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.