similar to: Using mocks

Displaying 20 results from an estimated 4000 matches similar to: "Using mocks"

2007 Feb 07
3
odd mock behavior
I''m seeing some odd behavior around the should_receive() when given a block combined with some cardinality. For example, with the following... my_mock.should_receive(:foo).twice do |i| puts i end ... the spec passes but i never gets puts''ed. With the following... my_mock.should_receive(:foo) do |i| puts i end ... i gets puts''ed twice but the spec fails because
2010 Jul 13
2
[Rspec] Difference between stub and message expectation with any_number_of_times
I''m wondering what''s the difference between stub and message expectation with any_number_of_times, for example: myMock = mock("mymock") myMock.stub!(:is_a?).with(MyClass).and_return(false) and myMock = mock("mymock") myMock.should_receive(:is_a?).with(MyClass).any_number_of_times.and_return(false) because is_a? may not be called at all, it just like a
2007 Jun 18
7
Testing for cross site scripting, etc.
Being new to testing and ruby, are there "standard" tests that can be done that test for things like cross site scripting and friends? If not, anyone have ideas on what I might do about testing those sorts of things? I''ll be using rails, also. Mike B. ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging
2007 Oct 11
2
Login testing ideas
I''ve been going through Pat''s example story and noticed that there was no checking for a bad login. I assume this is because that would have made the article bigger and more complicated than it needed to be. So the question that comes of of this is: How do folks normally handle the negative case? My plan was to just use another scenario, but as a new person to BDD/TDD,
2008 Jul 25
21
Problems with mock assigned to a constant
Hi all, Initially I thought this was a bug in the built-in mocking framework(and it still may be), but I better hash it out on the mailing list before I file/reopen the ticket: http://rspec.lighthouseapp.com/projects/5645/tickets/478-mocks-on-constants#ticket-478-6 I thought my example illustrated my problem, but obviously I was passing the wrong arguments to the mock. I revised my example to
2008 Nov 13
6
.with(:anything) issue
Hi, I''m using a expectation like this : repository.should_receive(:add_gem).with("test.txt", :anything) When I run my spec, it fails with the following message : Spec::Mocks::MockExpectationError in ''MiniGemServer should add a new gem to the repository after it has been uploaded'' #<MiniGemServer::Repository:0xb11164> expected :add_gem with
2007 Sep 18
2
rSpec / Nested Routes / Mocks
I''m having a terrible time trying to test a nested route with rSpec. I can''t seem to tell rSpec to expect the call @item.user. The following error message plagues me not matter how I try to fuss with the mock: Spec::Mocks::MockExpectationError in ''ItemsController handling POST / items should redirect to the new course on successful save'' Mock
2007 Aug 10
3
Using rcov and ouput to screen
I''d like to output my rcov data to the screen in ascii instead of html...is that possible using the rake spec:rcov command? Also, is there somewhere that will allow me to search the mail archives...I''m pretty sure someone else has asked similar questions. Thanks for the help. Mike B. ---------------------------------------------------------------- This message was sent
2007 Dec 29
15
Do you think it would look cleaner?
I was looking over some of my specs. I was thinking that the following: @game.should_receive(:name).and_return(''The Battle for Blaze'') @game.should_receive(:people).and_return(5000000) @game.should_receive(:activated).and_return(true) Would it look cleaner if I could do this instead? @game.should_recieve_and_return( :name => ''The Battle for Blaze''
2007 Aug 17
11
[rspec] looking for a simple refresher
I''ve been off the rspec for a few months and I''m trying to get back on it. 1) Spec::Mocks::MockExpectationError in ''TicketsController handling POST /tickets should create a new ticket'' Mock ''Ticket_1001'' expected :new with ({}) once, but received it 0 times ./spec/controllers/tickets_controller_spec.rb:16: script/spec:4: class
2007 Sep 30
9
Problems with testing nested routes using mocking
Hello forum I have there to files #----- virtual_host_controller.rb class VirtualHostsController < ApplicationController before_filter :capture_domain # GET /domain/1/virtual_hosts/1 def show @virtual_host = @domain.virtual_hosts.find(params[:id]) respond_to do |format| format.html # show.rhtml end end private def capture_domain if
2007 Jun 03
3
should_receive.again
Hi, It appears that if I have 2 should_receives in a row, the latest one overrides the previous one(s). If there isn''t one, could we add a way to accumulate them, such as @thing.should_receive(:method).and_return(@value) @thing.should_receive(:method).again.and_return(@value) @thing.should_receive(:method).again.and_return(@value) would be equivalent to
2007 Jan 05
4
How To Spec Controllers with Finders
Given this code (which renders rjs), I''m faced with the fixture- driven way of spec-ing or mocking. How the heck to you mock this so the code at line (2) and (4) work right? I''m still struggling with mocks but it seems like this can be done. Forgive the naivety of this question. 1. def change_quantity 2. @line_item = LineItem.find_by_id(params[:id]) 3. unless
2006 Jul 24
6
Mocking causes empty specification blocks
I''ve found myself mocking out a published api in my set-up method. This has led to some contexts having a large set-up and empty specifications. As the mocks get auto-verified, the specification blocks have nothing to do but serve as documentation. Does this sound bad? Chris
2007 Dec 04
10
Unexpected message on :attr_accessor
This may be a dumb noob issue, but I haven''t found any answers while seaching the forum-- I have a controller method def edit @user = User.find params[:id] @user.password_confirmation = @user.password end The User class has an "attr_accessor :password_confirmation" definition (so "password_confirmation" doesn''t exist in the users table). My spec
2006 Oct 23
6
overriding mock expectations
There is one annoyance I''m encountering with the Mock API in rSpec. Overall it works well, as far as dynamic mocks go ;)... but there''s this one thing... It doesn''t allow overriding of expectations. example: m = mock("blah") m.should_receive(:one).any_number_of_times().and_return(1) m.should_receive(:one).and_return(1) The second call to should_receive
2007 Oct 05
13
spec''ing view render partial collection, local variable not found
I''m trying to spec out a render partial collection but I get the following error 2) NoMethodError in ''/games/_game.rhtml should show game name'' undefined method `body'' for #<#<Class:0x316580c>:0x2f1154c> /Volumes/EXTERNAL/web/omenking.ca/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb:12:in `matches?''
2007 Aug 06
5
Problems with array mock
Hi everyone, I''m trying this in my helper spec and it didn''t work: @curr_odontogram.should_receive(''photos[1]'').and_return(@photo) and the error is: SyntaxError in ''PersonHelper Deberia devolverme un link para eliminar una foto'' compile error /home/gramos/src/rails/r-dental/config/../vendor/plugins/rspec/lib/spec/mocks/proxy.rb:99: syntax
2007 Aug 23
6
controller spec with model that validates_uniqueness
I want to use mocks and stubs to test the controller, but am having trouble getting my validation not to trigger. Here''s the code: # spec: Image.stub!(:find).and_return(@image) @image.should_receive(:save!).once.with(:any_args) put :update, :id => @image.id, :category_id => @category.id, :image => {:name => ''test'', :image_number =>
2007 Jun 15
6
problem getting started with stubbing in rails controller specs
Hello, Ingo! I''m copying your question to a new e-mail instead of replying to try to keep message threads separate. Have you tried setting up your expectation before issuing the get statement? For example, take this out of the setup block: get ''index'', :locale => ''en'' and move it after: