[rspec-users] What is the pattern for testing a time argument using argument matcher

2012-01-26 Thread Yi Wen
Say I do:

```ruby
object.method 5.days.ago
```

In the test I want to test using should_receive like:

```ruby
object.should_receive(:method).with(5.days.ago)
```

This will fail since two time objects aren't exact the same.

What is the general pattern for testing this in rspec?

Thanks
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


[rspec-users] html formatter

2010-08-16 Thread Yi Wen
For rspec 2.0, is there anyway we can specify which file the output should be 
written into when using html formatter easily? Thanks

Yi
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] predicate matching

2009-09-18 Thread Yi Wen
Ok, I guess in reality it will never make a difference if a predicate  
returns a nil or a false.


The behavior annoys me a little bit when I write a test that passes  
when the method itself does nothing (so that it returns nil). Any  
thoughts?


Thanks

Yi


On Sep 18, 2009, at 11:06 AM, David Chelimsky wrote:


On Fri, Sep 18, 2009 at 10:42 AM, Yi Wen  wrote:

Hi all,

I noticed that if I have a method named has_somthing? and I do:
object.should_not have_somthing and it failed (as expected) when  
the method

returns nil.


Actually, this should pass. The have_xxx and be_xxx matchers should
pass/fail based on truthiness, not true/false explicitly. For example:


require 'ostruct'

=> true

require 'spec/expectations'

=> true

include Spec::Matchers

=> Object

obj = OpenStruct.new(:has_foo? => nil)

=> #

obj.has_foo?

=> nil

obj.should_not have_foo

=> nil

obj.should have_foo

Spec::Expectations::ExpectationNotMetError: expected #has_foo?(nil) to
return true, got false

The message is admittedly wrong (should say "got nil" at the end, or
something else entirely), but the pass/fail is correct.

So it sounds like you're experiencing a bug of some kind on the
has_xxx matcher, not the be_xxx matcher, which is appears to be
behaving correctly based on what you wrote below. Please file a bug if
you can provide an example that I can run that I can see behaving
incorrectly.

HTH,
David






But if the method is something? and I do:
object.should_not be_something, and it succeeded (not what I  
expected) when

something? returns nil

Is this intended behavior or something I did was wrong? Thanks







Yi
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] predicate matching

2009-09-18 Thread Yi Wen
Sorry for the spam, but I was wrong: the *should_not have_something*  
also passed when the method returned nil.


On Sep 18, 2009, at 10:42 AM, Yi Wen wrote:


Hi all,

I noticed that if I have a method named has_somthing? and I do:
object.should_not have_somthing and it failed (as expected) when the  
method returns nil.


But if the method is something? and I do:
object.should_not be_something, and it succeeded (not what I  
expected) when something? returns nil


Is this intended behavior or something I did was wrong? Thanks

Yi


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


[rspec-users] predicate matching

2009-09-18 Thread Yi Wen

Hi all,

I noticed that if I have a method named has_somthing? and I do:
object.should_not have_somthing and it failed (as expected) when the  
method returns nil.


But if the method is something? and I do:
object.should_not be_something, and it succeeded (not what I expected)  
when something? returns nil


Is this intended behavior or something I did was wrong? Thanks

Yi
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


[rspec-users] [cucumber] table.hashes

2009-07-28 Thread Yi Wen

Hi,

I had a couple features failed with cucumber 0.3.90 because  
table.hashes is frozen so I cannot change the hashes anymore. Just  
wonder what's the reason behind the change? Thanks


Yi

 
___

rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Validations are making me want to scream. help please

2009-07-11 Thread Yi Wen
There is a validation error, which means you were trying to save the  
object somewhere. Check both your tests and code, to find out where.


On Jul 11, 2009, at 10:42 AM, Michael wrote:


Simply testing that my validations are working for a model called
Project.

MODEL
class Project < ActiveRecord::Base
 validates_presence_of :brief
end

SPEC
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe Project do
 before(:each) do
   @project = Project.new(:title => "project title", :brief =>
"project brief")
 end

 it "should create a new instance given valid attributes" do
   @project.should be_valid
 end
end

ERROR
ActiveRecord::RecordInvalid in 'Project should create a new instance
given valid attributes'
Validation failed: Brief can't be blank


POST
How on earth can that be failing? its driving me nuts, i have a few
other tests that check the exact same way(method taken from the Rspec
book) so why all the sudden would it stop working on a new model. Blah
thanks for any help.
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Noob syntax questions regarding rspec book...

2009-07-07 Thread Yi Wen

They are regex.
On Jul 7, 2009, at 10:35 AM, Chris Sund wrote:


Hey Everyone,

I've been working my way through the Rspec book trying to absorb and
understand everything. This is my first time with BDD and I'm just
trying to figure out some simple syntax stuff. My questions revolve
around some of the syntaxing used in the book. These are really simple
questions.


1.) Given /^the secret code is (. . . .)$/ do |code|
   Is (. . . .) simply a place holder? could I use something like
(- - - -) instead, or does it actually mean something?

2.) Then /^the mark should be (.*)$/ do |mark|
   Similar questionwhat does .* represent?



3.) In the following example why don't I pass   |guess| to the When
statement? I'm sure it has something to do with the (code.split)
syntax, I'm just not sure what.

When /^I guess (. . . .)$/ do |code|
@game.guess(code.split)
end


4.) And finally what does ("\n") do?

Then /^the mark should be (.*)$/ do |mark|
 @messenger.string.split("\n").should include(mark)
end





Thank You!

Chris
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] Spork 0.57

2009-06-19 Thread Yi Wen

Yup, removing the condition fixed the problem. Thanks!


On Jun 19, 2009, at 9:34 AM, David Chelimsky wrote:

On Fri, Jun 19, 2009 at 9:33 AM, David  
Chelimsky wrote:

On Fri, Jun 19, 2009 at 9:24 AM, Yi Wen wrote:

Hello,

I has spork 0.5.0 and worked fine. now I updated to spork 0.5.7  
which seems

to break the existing setting. The stack trace looks like this:

Using RSpec
Preloading Rails environment
Loading Spork.prefork block...
uninitialized constant MissingSourceFile (NameError)
/my_proj/vendor/gems/rspec-rails-1.2.6/lib/spec/rails.rb:5
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in
`gem_original_require'
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in  
`require'

/my_porj/spec/spec_helper.rb:8
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../ 
lib/spork.rb:11:in

`prefork'
/my_porj/spec/spec_helper.rb:4
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../ 
lib/spork/server.rb:166:in

`load'
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../ 
lib/spork/server.rb:166:in

`preload'
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../ 
lib/spork/app_framework/rails.rb:121:in

`preload'
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../ 
lib/spork/server.rb:162:in

`preload'
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../ 
lib/spork.rb:41:in

`exec_prefork'
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../ 
lib/spork/server.rb:148:in

`preload'
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../ 
lib/spork/runner.rb:95:in

`run'
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../ 
lib/spork/runner.rb:10:in

`run'
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/spork: 
11

/usr/local/bin/spork:19:in `load'
/usr/local/bin/spork:19


It's missing application_controller. THe environment.rb is loaded  
before

require 'spec/rails'. Any idea?


It's probably because of this:
https://rspec.lighthouseapp.com/projects/5645/tickets/839

If so, just remove the conditional from the line that requires  
environment.rb


If that's not it, you may want to try the spork google group:

http://groups.google.com/group/sporkgem








Thanks

Yi
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users




___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


[rspec-users] Spork 0.57

2009-06-19 Thread Yi Wen

Hello,

I has spork 0.5.0 and worked fine. now I updated to spork 0.5.7 which  
seems to break the existing setting. The stack trace looks like this:


Using RSpec
Preloading Rails environment
Loading Spork.prefork block...
uninitialized constant MissingSourceFile (NameError)
/my_proj/vendor/gems/rspec-rails-1.2.6/lib/spec/rails.rb:5
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in  
`gem_original_require'
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in  
`require'

/my_porj/spec/spec_helper.rb:8
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/ 
spork.rb:11:in `prefork'

/my_porj/spec/spec_helper.rb:4
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/ 
spork/server.rb:166:in `load'
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/ 
spork/server.rb:166:in `preload'
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/ 
spork/app_framework/rails.rb:121:in `preload'
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/ 
spork/server.rb:162:in `preload'
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/ 
spork.rb:41:in `exec_prefork'
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/ 
spork/server.rb:148:in `preload'
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/ 
spork/runner.rb:95:in `run'
/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/../lib/ 
spork/runner.rb:10:in `run'

/usr/local/lib/ruby/gems/1.8/gems/timcharper-spork-0.5.7/bin/spork:11
/usr/local/bin/spork:19:in `load'
/usr/local/bin/spork:19


It's missing application_controller. THe environment.rb is loaded  
before require 'spec/rails'. Any idea?


Thanks

Yi
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] wrong number of arguments (2 for 1)

2009-02-25 Thread Yi Wen
Unfortunately, it doesn't solve the problem. Thanks anyway

Yi

On Wed, Feb 25, 2009 at 5:18 PM, Mark Wilden  wrote:

> On Wed, Feb 25, 2009 at 2:50 PM, Yi Wen  wrote:
> > The following statement gave me "wrong number of arguments (2 for 1)" and
> it
> > is the only error. no stack trace.
> > presenter.stub!(:account).and_return account
> > any idea? Thanks
> > Yi
> >
> > ___
> > rspec-users mailing list
> > rspec-users@rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
>
> Put parentheses around 'account'.
>
> ///ark
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] wrong number of arguments (2 for 1)

2009-02-25 Thread Yi Wen
I haven't looked into it too much. But I believe it is because I implemented
method_missing and respond_to?, which probably conflicts with RSpec's
imlementations. I have been wanting to re-implement my functionality in
another way other than method_missing for a long time. It seems now is the
perfect time to do so. Thanks!

Yi


On Wed, Feb 25, 2009 at 5:04 PM, David Chelimsky wrote:

> On Wed, Feb 25, 2009 at 4:50 PM, Yi Wen  wrote:
> > The following statement gave me "wrong number of arguments (2 for 1)" and
> it
> > is the only error. no stack trace.
>
> try running with --backtrace
>
> > presenter.stub!(:account).and_return account
> > any idea? Thanks
> > Yi
> >
> > ___
> > rspec-users mailing list
> > rspec-users@rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

[rspec-users] wrong number of arguments (2 for 1)

2009-02-25 Thread Yi Wen
The following statement gave me "wrong number of arguments (2 for 1)" and it
is the only error. no stack trace.
presenter.stub!(:account).and_return account

any idea? Thanks

Yi
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] RSpec with edge rails (2.3 RC1)

2009-02-25 Thread Yi Wen
I have edge rails along with RSpec 1.1.99. works fine. What errors do you
get?

On Wed, Feb 25, 2009 at 1:24 PM, George Anderson
wrote:

> Hi,
>
> I'm failing miserably to get RSpec running with edge rails (2.3 RC1).
> I've tried building/installing the 1.1.99.1 gems from David's git
> repos (http://github.com/dchelimsky/rspec-rails and
> http://github.com/dchelimsky/rspec), but no luck.
>
> I realize "releases with a 4th partial [are] interim (unofficial)
> release[s]" and I should use them at my own risk.  Could someone
> kindly provide fairly explicit instructions for getting RSpec running
> with 2.3 RC1?  I suspect I'm making things more difficult than they
> are.
>
> If needed I can post error messages, but I'm not sure I'm on the right
> path to start with, so I don't think that would be helpful.
>
> Thanks,
>
> /g
>
> --
>
> George Anderson
>
> BenevolentCode LLC
> O: (410) 461-7553
> C: (410) 218-5185
>
> geo...@benevolentcode.com
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] [cucumber] Cucumber and CI

2009-02-22 Thread Yi Wen
yeah, you guys are probably right on this. I was just over stating. :)

Yi

On Sun, Feb 22, 2009 at 8:36 PM, Phlip  wrote:

> Yi Wen wrote:
>
>  I totally agree with you on this. I have a feeling a lot of people kind of
>> use cucumber as a sexy way for doing waterfall.
>>
>
> "Storytests" are very well represented in the Agile development community
> in general. Cucumber is a (slam-dunk) reinterpretation of Ward Cunningham's
> FIT concept.
>
> (Naturally, born of Java, FIT had no direct translation to Ruby, and that's
> probably a good thing!)
>
> It's only waterfall if your product-owner writes or commissions _thousands_
> of story tests before doing _any_ of them.
>
> I heavily suspect that the author of a cucumber "feature" can hardly wait
> to see it pass, and I suspect they will refrain from diverting energy to
> writing another one. That is the heart of Agile - the feedback loop.
>
> So what's the maximum number of cucumber features that anyone has ever seen
> on-deck but not yet passing? That's a bad metric, exactly like excess
> inventory in a warehouse.
>
> --
>  Phlip
>
>
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] [cucumber] Cucumber and CI

2009-02-22 Thread Yi Wen
Wait for an hour before I can checkin something is still too long for me.
I'd like to checkin every couple minutes most of time.

But I think to make each step just pending first and then make it green when
I finish implementation for the step makes sense. I probably will still use
unit tests passing as checkin points.

Thanks

Yi

On Sun, Feb 22, 2009 at 3:36 PM, aslak hellesoy wrote:

> On Sun, Feb 22, 2009 at 8:47 PM, Yi Wen  wrote:
> > The rhythm for wrking with cucumber advertised by http://cukes.info/ is
> to
> > write tests that fails first, then code that fixes it. Now my question
> is,
> > what is the implication when combine this with Continuous Integration?
> >
>
> * Nobody checks in code with failing tests (cucumber features, rspec
> tests, anything else).
> * If someone accidentally does, CI will run all tests and tell the team.
>
> > We all know when we do TDD/BDD in unit level, one test can be fixed
> fairly
> > quick in a coupe minutes and we can check in and kick off a build. It is
> a
> > ideal scene for doing CI: frequent checkin and fast feedback on build
> > results.
> >
> > Cucumber, as far as my understanding goes, works on feature level. It
> could
> > take people days to finish a cucumber feature. In the meantime, the
> cucumber
> > test remains broken. What do we do then? We cannot check in any code
> because
>
> A feature typically consists of several scenarios. You don't have to
> implement all scenarios before you commit. You don't have to write all
> scenarios when you start working on a feature. I recommend you never
> have more than one yellow scenario at a time.
>
> The same goes for scenarios, which consist of several steps.
>
> I recommend you commit every time you have made a step go from yellow
> to green (via red).
> This way, many successive commits will gradually build the whole feature.
>
> In my experience, getting a step to go from yellow to green rarely
> takes more than an hour (usually less).
> Is there anything preventing you from working this way?
>
> Aslak
>
> > that'll break the build. So we can only checkin code after several days?
> It
> > doesn't sound right to me. Any takes on this issue? Thanks in advance.
> >
> > Yi
> >
> >
> >
> > ___
> > rspec-users mailing list
> > rspec-users@rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
>
>
>
> --
> Aslak (::)
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] [cucumber] Cucumber and CI

2009-02-22 Thread Yi Wen
I totally agree with you on this. I have a feeling a lot of people kind of
use cucumber as a sexy way for doing waterfall.

On Sun, Feb 22, 2009 at 5:18 PM, Mark Wilden  wrote:

> On Sun, Feb 22, 2009 at 1:36 PM, aslak hellesoy
>  wrote:
> > You don't have to write all
> > scenarios when you start working on a feature. I recommend you never
> > have more than one yellow scenario at a time.
>
> Whereas I use scenarios as a "to-do" list. I'll keep adding them as I
> think of them or as they come up in discussion.
>
> ///ark
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

[rspec-users] [cucumber] Cucumber and CI

2009-02-22 Thread Yi Wen
The rhythm for wrking with cucumber advertised by http://cukes.info/ is to
write tests that fails first, then code that fixes it. Now my question is,
what is the implication when combine this with Continuous Integration?

We all know when we do TDD/BDD in unit level, one test can be fixed fairly
quick in a coupe minutes and we can check in and kick off a build. It is a
ideal scene for doing CI: frequent checkin and fast feedback on build
results.

Cucumber, as far as my understanding goes, works on feature level. It could
take people days to finish a cucumber feature. In the meantime, the cucumber
test remains broken. What do we do then? We cannot check in any code because
that'll break the build. So we can only checkin code after several days? It
doesn't sound right to me. Any takes on this issue? Thanks in advance.

Yi
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] validate_presence_of

2009-02-19 Thread Yi Wen
Good point, that's actually I am debating with myself everyday and haven't
got a clear answer. This is classical "calssic unit tester" vs. mockist war.
:)

Talking about this case:

1. I haven't checked how should valite_presence_of is implemented, but it
could pretty much be checking if the value is left blank. So it is behavior
tests

2. I couldn't see any reason why I would want to write my own version of
check_to_see_if_this_thingy_is_in_my_whatsis. So this is not a very
realistic assumption.

3. By checking if validation fails when a value is left blank, I am actually
kind of testing Rails and here's why: what if they introduce a bug in
validates_presence_of that makes my test break? What if they have a bug in
valid? to make my test break? To strictly just testing *my* own code, the
test should be something like
  Person.should_receive(:validates_presence_of).with(:email)

I am not really advocating the view of mockists. Just throw a question here.
:)

Yi

On Wed, Feb 18, 2009 at 11:40 PM, Stephen Eley  wrote:

> On Wed, Feb 18, 2009 at 11:42 PM, Yi Wen  wrote:
> >
> > Without this syntax sugar, we still have to test validates_presence_of to
> > make sure it's there and won't broken, right?
>
> Wrong.  You don't have to test validates_presence_of.  What matters,
> and therefore what you should test, is whether the model will complain
> at you if a particular value is left empty.
>
> validates_presence_of happens to be the name of the method in
> ActiveRecord that does that.  But if you decide to write your own
> check_to_see_if_this_thingy_is_in_my_whatsis() method that does the
> same thing, a good *behavior* spec will not break.  Because the
> behavior remains the same.
>
> If your spec breaks because you changed a method call, you're not
> testing behavior any more.  You're testing syntax.
>
>
>
> --
> Have Fun,
>   Steve Eley (sfe...@gmail.com)
>   ESCAPE POD - The Science Fiction Podcast Magazine
>   http://www.escapepod.org
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] validate_presence_of

2009-02-18 Thread Yi Wen
We should write a test/spec, whatever you call it, *first* before you want
your code. But it doesn't mean one who writes the spec/test will use a
monkey coding the code to fix the test. To be realistic, a programmer will
write this test, and implement it right away. Just like how TDD should be
done.

Without this syntax sugar, we still have to test validates_presence_of to
make sure it's there and won't broken, right? So this simple syntax is nice
because it's lees code to type in. I really don't see how trained monkeys
come into play in this scenario. :)

I am not a huge fan of "spec contract" for unit testing. Unit testing is a
tool for developers to write better, DRY-er and more loosely-coupled code.
At most it is a communication tool among developers. It's never meant to be
for non-technical / clients / business people. Cucumber might serve that
purpose.

Yi

On Wed, Feb 18, 2009 at 7:47 PM, Alex Satrapa  wrote:

> On 19/02/2009, at 11:39 , Fernando Perez wrote:
>
>  What's the point in testing validates_presence_of for a model? It's
>> already tested in the framework, and so readable that a quick glance on
>> the model says it all.
>>
>
> Some people want the spec to stand as a contract, so you can then hand the
> spec over to the proverbial trained monkeys and have them write all the
> necessary code from scratch exactly the way you want it written.
>
> These are not people I enjoy working with, so I play loose with the specs
> and only spec stuff that matters to me at the time, code that little bit,
> and get on with the next terribly pressing task.
>
> Alex
>
>
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] validate_presence_of

2009-02-17 Thread Yi Wen
ah! sorry, my bad. Thanks!

On Tue, Feb 17, 2009 at 6:56 PM, David Chelimsky wrote:

> On Tue, Feb 17, 2009 at 6:25 PM, Yi Wen  wrote:
> > Sorry for the spam, I relized there was a typo. It should be
> >it {should validate_presence_of(:login)}
> > It still didn't work
>
> Scrolling up a bit ...
>
>  "There are a few matcher libraries out there like
> rspec-on-rails-matchers that provide matchers like this
> validate_presence_of(:email)"
>
> validate_presence_of() is not part of rspec-rails. You can find
> libraries that offer comparable matchers at:
>
> http://github.com/thoughtbot/shoulda/tree/master
> http://github.com/joshknowles/rspec-on-rails-matchers/tree/master
> http://github.com/technoweenie/rspec_on_rails_on_crack/tree/master
> http://github.com/carlosbrando/remarkable/tree/master
>
> HTH,
> David
>
>
> >
> > On Tue, Feb 17, 2009 at 6:04 PM, Yi Wen  wrote:
> >>
> >> Hello,
> >>
> >> according to this post:
> >> http://blog.davidchelimsky.net/2009/1/13/rspec-1-1-12-is-released
> >>
> >> I should be able to write:
> >>
> >> describe User do
> >>   it {should valdate_presence_of(:login)}
> >> end
> >>
> >> with rspec 1.1.12
> >>
> >> But I got:
> >>
> >> NO NAME
> >> undefined method `valdate_presence_of' for
> >> #
> >>
> >> What did I do it wrong? Thanks for helping.
> >>
> >> Yi
> >
> >
> > ___
> > rspec-users mailing list
> > rspec-users@rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] validate_presence_of

2009-02-17 Thread Yi Wen
Sorry for the spam, I relized there was a typo. It should be
   it {should validate_presence_of(:login)}
It still didn't work

On Tue, Feb 17, 2009 at 6:04 PM, Yi Wen  wrote:

> Hello,
>
> according to this post:
> http://blog.davidchelimsky.net/2009/1/13/rspec-1-1-12-is-released
>
> I should be able to write:
>
> describe User do
>   it {should valdate_presence_of(:login)}
> end
>
> with rspec 1.1.12
>
> But I got:
>
> NO NAME
> undefined method `valdate_presence_of' for
> #
>
> What did I do it wrong? Thanks for helping.
>
> Yi
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

[rspec-users] validate_presence_of

2009-02-17 Thread Yi Wen
Hello,

according to this post:
http://blog.davidchelimsky.net/2009/1/13/rspec-1-1-12-is-released

I should be able to write:

describe User do
  it {should valdate_presence_of(:login)}
end

with rspec 1.1.12

But I got:

NO NAME
undefined method `valdate_presence_of' for
#

What did I do it wrong? Thanks for helping.

Yi
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

[rspec-users] Is RSpec Ruby1.9 ready?

2009-02-06 Thread Yi Wen
Hi,

I saw a message on Nov, 2008 in this mailing list from David:

"I'm not sure how to fix that problem, but before you go much further
you should know that RSpec does not yet run under 1.9. It's something
I want to raise in priority soon, and patches are welcome, but that's
the state of things today."


And I haven't seen any update on this issue since then. But according to this
site , RSpec works under Ruby 1.9.

So Is there any "official" response on this issue?

Thanks

Yi
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] OK... What is ... fu ?

2009-01-30 Thread Yi Wen
This "Fu" you refer to is actually different than "Fu" as in "Kung-Fu". The
fu as in kung-fu by itself, means husband. In Ancient Chinese, it also means
wise person, such as confucius(Kong Fu Zi).

On Fri, Jan 30, 2009 at 9:06 AM, David Chelimsky wrote:

> On Fri, Jan 30, 2009 at 8:49 AM, James Byrne  wrote:
> > Pardon my ignorance, but exactly what does _fu mean WRT Ruby plugins,
> > gems and such?
> >
> > I have run across this suffix a number of times in Ruby and Rails,
> > always in connection with some add-on or extension.  In the original
> > context that I encountered '_fu' I inferred that it probably stood for
> > file upload.  However, its widespread use in other contexts evidently
> > disproves this interpretation. So, does it have a meaning?  Does it
> > derive from the foo in foobar? Does it stand for functional update? Or,
> > is it an obscure cultural reference to Ruby's Japanese origins?
>
> http://english.peopledaily.com.cn/200601/25/eng20060125_238295.html
>
> > --
> > Posted via http://www.ruby-forum.com/.
> > ___
> > rspec-users mailing list
> > rspec-users@rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] Nosy controller specs

2008-12-11 Thread Yi Wen
yeah, instead of using Post.find(:all) in your controller, use a method like
Post.all_posts, or some names like that. Then in the controller spec, you
go:
Post.should_receive(:all_posts) and leave the implementation detail of this
method to the Post model. Technically speaking, this all_posts more belongs
to Service layer though.

Yi

On Thu, Dec 11, 2008 at 5:48 AM, Andrew Premdas  wrote:

> Looking at generated controller specs we tend to get something like
>
> describe PostsController do
>   describe "handling GET /posts" do
>
> before(:each) do
>   @post = mock_model(Post)
>   Post.stub!(:find).and_return([...@post])
> end
>
> def do_get
>   get :index
> end
> ...
>
> it "should find all posts" do
>   Post.should_receive(:find).with(:all).and_return([...@post])
>   do_get
> end
>
> Now this last spec "should find all posts" is nosy is far as I'm concerned
> in that its specifying how the model should get all the posts (i.e. white
> box testing) rather than checking the result i.e. that its got @post back.
> So now if I change the model so that "all posts" is for example "all posts
> in last year" because there is a new business rule that we don't show posts
> over a year old then my controller spec fails. Now it seems to me that I
> should only have to change my model specs when I make this sort of change,
> this implementation details is none of the controllers business
>
> So a couple of things
>
> 1) Am I right about this?
> 2) If so is there a better way to still use the mock for speed but not be
> nosy
> 3) Should the default controller generators be re-written
>
> TIA
>
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] `add_scenario': wrong, number of arguments (1 for 2)

2008-11-18 Thread Yi Wen
Weird, it seems like a bug to me:

  def Scenario(name, &proc)
add_scenario(name, &proc)
  end

  def add_scenario(name, line, &proc)
scenario = Scenario.new(self, name, line, &proc)
@scenarios << scenario
scenario
  end

Scenario lacks a "line" argument when calling add_scenario

Yi

On Tue, Nov 18, 2008 at 3:16 PM, Bret Pettichord <[EMAIL PROTECTED]>wrote:

> I am trying to get some old "rbehave" scripts working with cucumber. I am
> running into an error. I get the same error when I run the
> "calculator_ruby_features" example.
>
> Any suggestions?
>
> Bret
>
> C:\work\cucumber\examples\calculator_ruby_features>rake features
> (in C:/work/cucumber/examples/calculator_ruby_features)
> You must gem install win32console to get coloured output on this ruby
> platform (
> i386-mswin32)
> C:/work/cucumber/bin/../lib/cucumber/tree/feature.rb:37:in `add_scenario':
> wrong
> number of arguments (1 for 2) (ArgumentError)
>   from C:/work/cucumber/bin/../lib/cucumber/tree/feature.rb:37:in
> `Scenari
> o'
>   from ./features/addition.rb:8
>   from C:/work/cucumber/bin/../lib/cucumber/tree/feature.rb:13:in
> `instanc
> e_eval'
>   from C:/work/cucumber/bin/../lib/cucumber/tree/feature.rb:13:in
> `initial
> ize'
>   from C:/work/cucumber/bin/../lib/cucumber/tree.rb:8:in `new'
>   from C:/work/cucumber/bin/../lib/cucumber/tree.rb:8:in `Feature'
>   from ./features/addition.rb:6
>   from
> c:/ruby-186-26/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27
> :in `gem_original_require'
>   from
> c:/ruby-186-26/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27
> :in `require'
>   from C:/work/cucumber/bin/../lib/cucumber/cli.rb:188:in
> `require_files'
>   from C:/work/cucumber/bin/../lib/cucumber/cli.rb:186:in `each'
>   from C:/work/cucumber/bin/../lib/cucumber/cli.rb:186:in
> `require_files'
>   from C:/work/cucumber/bin/../lib/cucumber/cli.rb:165:in `execute!'
>   from C:/work/cucumber/bin/../lib/cucumber/cli.rb:11:in `execute'
>   from C:/work/cucumber/bin/cucumber:5
> rake aborted!
> Command failed with status (1): [c:/ruby-186-26/bin/ruby -I
> "C:/work/cucumb...]
>
> (See full trace by running task with --trace)
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

[rspec-users] How to use config.gem for rspec and rspec-rails

2008-11-17 Thread Yi Wen
Hi,

Is there anyway I can specify
config.gem rspec :lib => "spec"
config.gem rspec-rails :lib => "spec/rails"

 in my test.rb?

Basically I got this after I specify rspec
rake gems:unpack RAILS_ENV=test
(in /home/ywen/projects/kod)
rake aborted!
uninitialized constant Spec::Rake
/home/ywen/projects/kod/Rakefile:10
(See full trace by running task with --trace)

Thanks

yi
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] Should acceptance tests be run against a production environment?

2008-10-29 Thread Yi Wen
I agree. I have seen way too many times selenium tests are OK but bugs
appear in production. Not only should we run selenium tests against
production environment, but also they should be run on a production like
environment, such as, same OS, same setting (behind Apache, or whatever HTTP
servers, etc.)

On Tue, Oct 28, 2008 at 12:08 PM, Pat Maddox <[EMAIL PROTECTED]> wrote:

> When you do end-to-end acceptance testing with Selenium, I think it
> should be run against a production environment.  Not THE production
> environment, mind you, but simply a new Rails app running with
> RAILS_ENV=production.  Also, transactional fixtures should be turned
> off.  This is so that the app runs as closely as possible to how it does
> from a regular user's perspective.  Models and pages get cached,
> transactions commit and rollback as they're defined, etc.  What do you
> think?  Am I off base here?
>
> Pat
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] private methode

2008-10-10 Thread Yi Wen
IMHO, one should never directly test a private method. So I prefer the
second way you mentioned in your email.

Better yet, think of why you want to test a private method. Is it too
complicated? If this is the case, way too often this private method should
not really belong to the class it's currently in. This class might be doing
too much and this private method is not part of core functionality this
class provides (or else it should be made public as part of the class's
interface). So you may want to refactor the code to find a proper home for
your private method and make it public in that class and you can unit
testing this new public method.

Yi

On Fri, Oct 10, 2008 at 2:40 PM, Anita Anita <[EMAIL PROTECTED]> wrote:

> Hi,
>
> Can I test private methods directly?
> Or should I pass by the methods that are calling these private methods?
> Or can I make the method private after testing?
> What is the best way?
>
> Thank you
> --
> Posted via http://www.ruby-forum.com/.
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] How to unit test code that connects to the external resources?

2008-09-08 Thread Yi Wen
def run
url = URI.parse(run_path)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = use_ssl_for_run
http.start {
req = Net::HTTP::Get.new run_path
req.basic_auth self.class.user, self.class.password
@response = http.request(req)
}
end

run_path and use_ssl_for_run are both instance methods. run

On Mon, Sep 8, 2008 at 3:23 PM, Chuck Remes <[EMAIL PROTECTED]> wrote:

>
> On Sep 8, 2008, at 12:12 PM, Yi Wen wrote:
>
> By external resources, I mean, the code start a http connection and GET
> xmls from the url specified. I will definitely not rely my unit test on an
> external url or anything like that. But how do I unit test the method? I
> mean, I can basically mock the Net::HTTP, but then the test will pretty much
> be like the method itself, except all the calls will be replaced by stub! or
> should_receive.
>
> I made this method as simple as possible. There is no *if* statements or
> loop in the method, should I just NOT test this one?
>
> Thanks for any ideas
>
>
> Show us the code so we can help.
>
> cr
>
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

[rspec-users] How to unit test code that connects to the external resources?

2008-09-08 Thread Yi Wen
By external resources, I mean, the code start a http connection and GET xmls
from the url specified. I will definitely not rely my unit test on an
external url or anything like that. But how do I unit test the method? I
mean, I can basically mock the Net::HTTP, but then the test will pretty much
be like the method itself, except all the calls will be replaced by stub! or
should_receive.

I made this method as simple as possible. There is no *if* statements or
loop in the method, should I just NOT test this one?

Thanks for any ideas

Yi
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] Colorize story output

2008-07-08 Thread Yi Wen
Actually, for the completeness. please see this:
http://yiwenandsoftware.wordpress.com/2008/06/25/intergrate-rspec-story-runner-in-cruisecontrolrb-build-with-html-report/

On Tue, Jul 8, 2008 at 8:59 AM, Yi Wen <[EMAIL PROTECTED]> wrote:

> yes. -f html
>
>
> On Tue, Jul 8, 2008 at 8:41 AM, aidy lewis <[EMAIL PROTECTED]>
> wrote:
>
>> Hi David,
>>
>> > >
>> >
>> > ruby stories/all.rb -c
>> >
>>
>> Fantastic. Is it possible to create HTML from this?
>>
>> Aidy
>> ___
>> rspec-users mailing list
>> rspec-users@rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
>
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] Colorize story output

2008-07-08 Thread Yi Wen
yes. -f html

On Tue, Jul 8, 2008 at 8:41 AM, aidy lewis <[EMAIL PROTECTED]>
wrote:

> Hi David,
>
> > >
> >
> > ruby stories/all.rb -c
> >
>
> Fantastic. Is it possible to create HTML from this?
>
> Aidy
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: [rspec-users] auto-generated descriptions

2008-07-05 Thread Yi Wen
+1. This is a smart.

On Fri, Jul 4, 2008 at 9:18 PM, Steve Eley <[EMAIL PROTECTED]> wrote:
> On Fri, Jul 4, 2008 at 4:45 PM, David Chelimsky <[EMAIL PROTECTED]> wrote:
>>
>> So - how bad do you think this would suck to remove that feature? Are you
>> using it yourself?
>
> I'm not, but would it be impractical to extract it out into some sort
> of module or helper and tell people to include it in their config.*
> block if they want to use it?
>
>
> --
> Have Fun,
> Steve Eley
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


[rspec-users] DRY up story

2008-06-24 Thread Yi Wen
In David's presentation @ RailsConf, he has this example:

Story: measure progress towards registration goals
As a conference organizer
I want to see a report of registrations
So that I can measure progress towards registration goals

Scenario: one registration shows as 1%
Given a goal of 200 registrations
When 1 attendee registers
Then the goal should be 1% achieved

Scenario: one registration less than the goal shows as 99%
Given a goal of 200 registrations
When 199 attendees register
Then the goal should be 99% achieved

Notice that Given part is exactly the same for both scenarios. Does it
possible to DRY up it a little bit by putting Given up to right after
Story part? Or it is just too crazy?

Yi
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


[rspec-users] Story HTML output

2008-06-24 Thread Yi Wen
Hi,

If I write the HTML format stories output to
~/ccrb_build-build_number/Stories/index.html. To get all styles
rendered, I also need to copy
/vendor/plugins/rspec/story_server/prototype/stylesheets/ and
/vendor/plugins/rspec/story_server/prototype/javascripts/ to the
~/ccrb_build-build_number/Stories/.

Just wonder is this the right way to do it? or there is a
better/preferred way? Thanks

Yi
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] before_save model callback rspec testing

2008-06-24 Thread Yi Wen
That's because you executed the same creation code into the
script/console, which has nothing to do with RSpec, and still get the
same error message, right?

Yi

On Tue, Jun 24, 2008 at 2:56 AM, Csongor Bartus <[EMAIL PROTECTED]> wrote:
> Yi Wen wrote:
>> Well, at least now we know this is nothing to do with RSpec. My
>> suggestion is that you comment out the code which will be executed
>> during a creation, bit by bit in User (such as before_save) and try to
>> create a user. In this way you can pinpoint where the problem is.
>
> Thanks a lot Yi Wen,
>
> Now I'll find out easier where the bug lies ...
> But how did you realized the bug is not in RSpec but in the code?
>
>
> --
> Posted via http://www.ruby-forum.com/.
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] before_save model callback rspec testing

2008-06-23 Thread Yi Wen
Well, at least now we know this is nothing to do with RSpec. My
suggestion is that you comment out the code which will be executed
during a creation, bit by bit in User (such as before_save) and try to
create a user. In this way you can pinpoint where the problem is.


On Mon, Jun 23, 2008 at 10:26 AM, Csongor Bartus <[EMAIL PROTECTED]> wrote:
> Yi Wen wrote:
>> You don't have attr_accessor :password, :password_confirmation in
>> User, do you? You may want to add this and try again
>
> I had :password, I've added :password_confirmation but still the same:
>
>>> u = User.create!(:login => "test", :email => "[EMAIL PROTECTED]", :password 
>>> => "test123", :password_confirmation => "test123")
> NoMethodError: You have a nil object when you didn't expect it!
> You might have expected an instance of Array.
> The error occurred while evaluating nil.each
>from
> ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1671:in
> `attributes='
>from
> ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1505:in
> `initialize_without_callbacks'
>from
> ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/callbacks.rb:225:in
> `initialize'
>from
> ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/validations.rb:726:in
> `new'
>from
> ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/validations.rb:726:in
> `create!'
>from (irb):1
>>>
> --
> Posted via http://www.ruby-forum.com/.
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] before_save model callback rspec testing

2008-06-23 Thread Yi Wen
You don't have attr_accessor :password, :password_confirmation in
User, do you? You may want to add this and try again

On Mon, Jun 23, 2008 at 9:59 AM, Csongor Bartus <[EMAIL PROTECTED]> wrote:
> Yi Wen wrote:
>> fire up script/console and copy line 82 and try it out. and report the
>> result here.
>
>>> u = User.create!(:login => "test", :email => "[EMAIL PROTECTED]", :password 
>>> => "test123", :password_confirmation => "test123")
> NoMethodError: You have a nil object when you didn't expect it!
> You might have expected an instance of Array.
> The error occurred while evaluating nil.each
>from
> ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1671:in
> `attributes='
>from
> ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:1505:in
> `initialize_without_callbacks'
>from
> ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/callbacks.rb:225:in
> `initialize'
>from
> ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/validations.rb:726:in
> `new'
>from
> ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/validations.rb:726:in
> `create!'
>from (irb):1
>>>
> --
> Posted via http://www.ruby-forum.com/.
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] before_save model callback rspec testing

2008-06-23 Thread Yi Wen
fire up script/console and copy line 82 and try it out. and report the
result here.

On Fri, Jun 20, 2008 at 11:11 AM, Csongor Bartus <[EMAIL PROTECTED]> wrote:
> David Chelimsky wrote:
>
>>
>> Try using create! or save! - I'll bet the record is not being saved
>> correctly and you're not seeing the error.
>
> done, still the same errors (exactly)
> --
> Posted via http://www.ruby-forum.com/.
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] before_save model callback rspec testing

2008-06-20 Thread Yi Wen
user.should_receive(:encrypt_password).with(your_password)
user.save

Is this what you want?

On Fri, Jun 20, 2008 at 10:12 AM, Csongor Bartus <[EMAIL PROTECTED]> wrote:
> hi all,
>
> i'm learning rspec and i can't figure out how to test if a callback is
> executed in a model.
>
> my model code is:
>
> class User < ActiveRecord::Base
>  before_save :encrypt_password
>
> ...
>
>  def encrypt(password)
>self.class.encrypt(password, salt)
>  end
>
>
> thanks a lot,
> cs.
> --
> Posted via http://www.ruby-forum.com/.
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] RSpec for testing REST webservices? (Not Rails)

2008-06-06 Thread Yi Wen
I use http-access2 (http://dev.ctor.org/http-access2) for make requests.
I also have a custom WebServiceExampleGroup to do setup work there.

On Fri, Jun 6, 2008 at 11:20 AM, Pol Llovet <[EMAIL PROTECTED]> wrote:
> I am interested in this also, anyone out there have some best practices?
>
> --
> Posted via http://www.ruby-forum.com/.
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


Re: [rspec-users] RailsExampleGroup

2008-05-23 Thread Yi Wen
Well, I use this for driving selenium RC. So the approach I am using
is to setup some data, and then invoke selenium to interact with a
test server. Apparently the test server uses another connection. Would
you suggest a better way to handle this? It will be the same for doing
functional testing on web services. What's the "standard way" of doing
it?

Yi

On 23 May 2008, at 19:53, Yi Wen wrote:

> It's not in the database. It looks to me the data is not actually
> inserted into the DB at all, just somehow buffered somewhere.

It's stored in a transaction, so the only place you can see the data
is from the same connection.  Make another connection (by
reconnecting) and you are protected from seeing that data.

Why do you want to see this intermediate state of the database from
another connection anyway?  It's an unusual thing to want to do.

Ashley
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users


[rspec-users] RailsExampleGroup

2008-05-23 Thread Yi Wen
So I have a describe which is a subclass of RailsExampleGroup. I inserted
some data into my database, and reconnect! my connection. Before reconnect,
finding the data I just created is fine. The data cannot be found, after
reconnection, the data is gone. It's not in the database. It looks to me the
data is not actually inserted into the DB at all, just somehow buffered
somewhere. Would anybody know why? thanks.

Now the workaround is to have a separate class doing all DB operations, but
I am still curious why RSpec does this, for speed reason?

Yi
___
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users