[rspec-users] variable strange change

2010-09-15 Thread Zhenning Guan
class User has_many :mads def mad Mad.find_by_user_id(id) end end class God belongs_to :mad belongs_to :user belongs_to :sender, :class_name => "User", :foreign_key => "sender_id" def strange_change! God.transaction do puts mad.nil?#the first time put is false

Re: [rspec-users] how to wrtie this test?(test true but change when refactor)

2010-09-07 Thread Zhenning Guan
> In your original post you said you were getting two bankbook items after > the change. Do you want one or two? And where is the 2nd one coming > from? I always want one . after change the code I got two. and the original test doesn't fail. def process! #transaction block bank.withdraw

Re: [rspec-users] how to wrtie this test?(test true but change when refactor)

2010-09-06 Thread Zhenning Guan
David Chelimsky wrote: > By "before and after" I meant what the code looked like before you made > the change you want to make, and what it looked like after the change. sorry I misunderstood your word. def process! #transaction block bankbook = self.bankbooks.build bankbook = user.

Re: [rspec-users] how to wrtie this test?(test true but change when refactor)

2010-09-06 Thread Zhenning Guan
David Chelimsky wrote: > I'm having a hard time understanding what you're trying to do here. Can > you please post the full before and after code and spec listing in a > gist or pastie? > > http://gist.github.com > http://pastie.org the before just mock a user. and user request to withdraw mone

[rspec-users] how to wrtie this test?(test true but change when refactor)

2010-09-04 Thread Zhenning Guan
def process! #transaction block bankbook = self.bankbooks.build bankbook = user.bank.bankbooks.build bankbook.withdraw #end end it "should process the withdrawal request" do #something here omit withdrawal.process! @ning.bankbooks.last.price.should == BigDecimal('1.0

[rspec-users] there should be one test or two?

2010-08-26 Thread Zhenning Guan
in real world, when user deposit money into their bank, bank have money and can check deposit record. so what would it be in rspec? it 'should be deposit $10' user.bank.deposit(10) user.bank.deposit.saving.should == 10 end about test , should be deposit $10 is clear? maybe 'should deposit $10

[rspec-users] should_receive break the method chain?

2010-07-29 Thread Zhenning Guan
class A def process @b.calculate end end it 'should change b calculate value' do @b.should_receive(:calculate) @a.process @b.calculae_value.should == 'after_calculae' end it will fail, if I comment out #...@b.should_receive(:calculate), the test pass, or if comment out #...@b.calculae_v

Re: [rspec-users] [rails] shoud I test validate_presentence_of series?

2010-07-21 Thread Zhenning Guan
thank you all. :) -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users

[rspec-users] [rails] shoud I test validate_presentence_of series?

2010-07-21 Thread Zhenning Guan
Suppose I have a model Forum, have some attributes, title, content, tag.so I do it in Forum model. validates_presence_of :title validates_presence_of :tag validates_presence_of :content. when I added validateds_presence_of, rails will restrict the attribute not be empty, when save record. so afte

[rspec-users] how to mock a Net::Http object?

2010-03-02 Thread Zhenning Guan
one_data = Net::HTTP.post_form(URI.parse(country_site), {'country' => "american"}) two_data = Net::HTTP.post_form(URI.parse(visit_site), {'country' => "english"}) I have a code similar like above code in my application, so how to mock a a object like above? if only post_from once, I just need to s

Re: [rspec-users] how to test a observer model?

2009-11-26 Thread Zhenning Guan
Matt Wynne wrote: > You can do something like this to sense the value passed to the user > object: > Obviously the precise specifications of the key are up to you and your > stakeholders, but that should show you how you can test it. > > cheers, > Matt > > http://mattwynne.net > +447974 430184 t

[rspec-users] how to test a observer model?

2009-11-25 Thread Zhenning Guan
I have a user_observer, code like this: def after_create(user) UserMailer.deliver_signup_notification(user) user.random_key = random_key_method user.save end before do @user = mock_model(User) @user_observer = UserObserver.instance end UserMailer.should_receive(:deliver_signup_no

[rspec-users] why should_receive failure?

2009-07-14 Thread Zhenning Guan
class PeepCode def awesome "awesome" end end describe PeepCode do it "should fuck" do PeepCode.new.should_receive(:awesome).and_return("awesome") end end - Spec::Mocks::MockExpectationError in 'PeepCode should fuck' # expected :awesome wit

[rspec-users] why should_receive doesn't work, but stub does.

2009-07-14 Thread Zhenning Guan
before(:each) do @myinstance = GetHtml.new end it "should be a Hyricot" do hy = open('test.html') {|f| Hpricot f} @myinstance.should_receive(:find_html).with("file:///test_url").and_return(hy) end ++ it "should be a Hyricot" do hy = o

Re: [rspec-users] what does :save => true mean in mock_model ?

2009-06-27 Thread Zhenning Guan
one more question. Forecast.stub!(:new).and_return(@forecast) Forecast.should_receive(:new).with(anything()).and_return(@forecast) what's the different between stub! and should_receive ? -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing

Re: [rspec-users] what does :save => true mean in mock_model ?

2009-06-27 Thread Zhenning Guan
David Chelimsky wrote: clear, thank you David -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users

[rspec-users] what does :save => true mean in mock_model ?

2009-06-27 Thread Zhenning Guan
@weather = mock_model(Weather, :id => "1") @forecast = mock_model(Forecast, :weather => @weather, :save => true) what's the different between with :save => true or without it? -- Posted via http://www.ruby-forum.com/. ___ rspec-users mailing list rspec

[rspec-users] how to deal with redirect_to on cucumber?

2009-05-20 Thread Zhenning Guan
I have a controller name forums and a action like this: def show redirect_to forum_topics_path(:forum_id => params[:id]) end my scenario is (not completed) == Scenario: User input data correct When I run to the forum 1 -- When /^I run to the (.*)$/ do |topic_lists| visit path

Re: [rspec-users] Forum.count.should, should doesn't work?

2009-05-20 Thread Zhenning Guan
David Chelimsky wrote: > On Tue, May 19, 2009 at 10:09 AM, Zhenning Guan > wrote: >> features/step_definitions/webrat_steps.rb:10 >> >> 1 scenario (1 failed) >> 2 steps (1 failed, 1 passed) >> >> === >> Forum.count == counts.to_i does fine > &

Re: [rspec-users] Forum.count.should, should doesn't work?

2009-05-20 Thread Zhenning Guan
Zhenning Guan wrote: > David Chelimsky wrote: >> On Tue, May 19, 2009 at 10:09 AM, Zhenning Guan >> wrote: >>> features/step_definitions/webrat_steps.rb:10 >>> >>> 1 scenario (1 failed) >>> 2 steps (1 failed, 1 passed) >>> >>&

[rspec-users] Forum.count.should, should doesn't work?

2009-05-19 Thread Zhenning Guan
Scenario: List Tasks Then I should have 3 forums - Then /^I should have ([0-9]+) forums$/ do |counts| Forum.count.should == counts.to_i end When I go to the homepage # features/step_definitions/webrat_steps.rb:10 Then I should have 3 forums # features/step_definitions

[rspec-users] what's wrong with my newbie cucumber test?

2009-05-16 Thread Zhenning Guan
forums.feature = Feature: Tasks In order to keep track of tasks People should be able to Create a list of tasks Scenario: List Tasks When I go to the homepage = forums_steps.rb = When /^I go to the homepage$/ do visit "/forums" end = when I run rake features. == Scenario: List Tasks# f

[rspec-users] what is the context?

2009-03-29 Thread Zhenning Guan
describe MovieList do context "when first created" do it "should be empty" do movie_list = MovieList.new movie_list.should be_empty end end end what is the context work for? -- Posted via http://www.ruby-forum.com/. ___ rspec-us

[rspec-users] what's the different between ([...@weather]) and (@weather)?

2009-03-25 Thread Zhenning Guan
before do @weather = mock_model(Weather) Weather.stub!(:find).and_return([...@weather]) end I saw this code on peepcode, but I'm a little confused the and_return([...@weather]). mostly, we just and_return(@weather), don't we? so, what is the meaning of and_return([...@weather]) ? -- Posted v

[rspec-users] what's the meaning of to_param?

2009-03-19 Thread Zhenning Guan
usually, I just use this way. = @weather = mock_model(Weather) = but recently I saw this. so what's the :to_param and :save options meaning? == @weather = mock_model(Weather, :to_param => "1", :save => true) == -- Posted via http://www.ruby-forum.com/. __

[rspec-users] how to test this view with Rspec

2009-03-14 Thread Zhenning Guan
= flash_messages - @user = User.find(1) - if current_user == @user %new_forum= link_to 'new forum', new_forum_path - @forum.each do |f| .group = link_to f.name, forum_path(f) - if current_user == @user = link_to 'edit', edit_forum_path(f) = link_to 'destroy', forum_path(f),