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
if
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 ==
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
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
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
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
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
thank you.
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
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 =
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'
#PeepCode:0xb7aa3bbc
@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
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
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
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
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-users
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
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/.
17 matches
Mail list logo