[rspec-users] Rspec controller test

2007-08-07 Thread Shaker

Great Hi to everybody!
I am currently working on a project which tests the controllers using rspec.
I came across some methods in the controller which do not generate any
actions at all. However, they still need testing! Some of these methods do
require parameters. I am wondering how I can pass the test cases as the
parameters to these targeted methods in the controller spec?? Below is a
simple example for illustration:
in the controller:
def method_for_test(parameter_1, parameter_2)
#do some coding
#no action
end

in the controller_spec:
it "should test the method_for_test" do
parameter_1
parameter_2
??how to pass them to method_for_test
end

Thank you all in advance.
-- 
View this message in context: 
http://www.nabble.com/Rspec-controller-test-tf4229016.html#a12030820
Sent from the rspec-users mailing list archive at Nabble.com.

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


[rspec-users] Failed to pass arguments to controller method

2007-08-07 Thread Shaker

Good morning to everyone:
So weird!!
I got a method called apply_settings(arg1, arg2) in the controller to be
tested. In the controller spec, I of course called the method. 
In the controller:
def apply_settings(arg1, arg2) #where arg1 is a hash, and arg2 is an
array of object
  #do some coding
end
In the controller spec:
before(:each) do
  @controller = Controller.new
end

it "should test the apply_settings" do
  @controller.apply_settings(Hash.new, array_of_object) #where the
arguments are exactly some format

#as required
end

However, it yielded "wrong number of arguments(0 for 1)" error after I ran
the spec. It there anything wrong in my spec?

Cheers!

-- 
View this message in context: 
http://www.nabble.com/Failed-to-pass-arguments-to-controller-method-tf4233633.html#a12045114
Sent from the rspec-users mailing list archive at Nabble.com.

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


[rspec-users] Problem of using fixture in Rspec

2007-08-12 Thread Shaker

Dear Fellows:
I was using fixtures in the model tests using Rspec. I found that the
test data specified in the fixtures was stored in the test database once I
ran the spec and won't be removed anyway. Is my observation correct?
There might be another problem regarding the fixtures. When I ran the
specs one by one, it was working. However, it failed when I tried to run all
the specs in one command. It seemed that the test data which was modified by
one spec caused the other spec which accessed that particular data to fail.
In other words, the data is actually kind of public to all specs, so the
specs shares one copy of test data. 
If my observation is correct, are there any ways to overcome these
problems? Is it possible that each single spec owns its test data so that
the modifications on the data will not affect other specs?
Cheers! 
-- 
View this message in context: 
http://www.nabble.com/Problem-of-using-fixture-in-Rspec-tf4258669.html#a12119520
Sent from the rspec-users mailing list archive at Nabble.com.

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


[rspec-users] How to use expect_render?

2007-08-13 Thread Shaker

Hi:
I am a rspec beginner. I have scratched my head for the whole afternoon,
trying to figure out a way of writing render expectation in controller spec.
However, I failed. It kept telling me that the 'expect_render' was an
undefined method. I have installed rspec 1.0.8 and rspec_on_rails as well.
Below is the controller to be tested. 

Controller
def index
  pre = Array.new
  render :partial=>'index', :layout=>false, :locals=>{:pre=>pre} 
end

My controller spec
before do
  @controller = MyController.new
end
it "should render the index partial" do
  @controller.expect_render(:partial=>'index', :layout=>false) #I don't
know how to expect the :locals
end

As I mentioned, the spec failed , saying that "Undefined method
'expect_render' ". There might be some mistakes in my "before" block. Do I
need to mock the controller or something else? Anyway, do any one know how
to fix the problem? It will be even better if you guys could show me a piece
of example code. 
Thanks!!
-- 
View this message in context: 
http://www.nabble.com/How-to-use-expect_render--tf4259590.html#a12121894
Sent from the rspec-users mailing list archive at Nabble.com.

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


Re: [rspec-users] How to use expect_render?

2007-08-13 Thread Shaker

Hello, Aslak:
I know we could do template.expect_render somehow, although I haven't
tried that out. But the rspec developer said that we could now actually use
controller.expect_render in controller specs, which caused me confused. You
may want to have a look at this:
http://rspec.rubyforge.org/documentation/rails/writing/controllers.html
writing controller spec 
Thanks, regards. 

aslak hellesoy wrote:
> 
> On 8/13/07, Shaker <[EMAIL PROTECTED]> wrote:
>>
>> Hi:
>> I am a rspec beginner. I have scratched my head for the whole
>> afternoon,
>> trying to figure out a way of writing render expectation in controller
>> spec.
>> However, I failed. It kept telling me that the 'expect_render' was an
>> undefined method. I have installed rspec 1.0.8 and rspec_on_rails as
>> well.
>> Below is the controller to be tested.
>>
>> Controller
>> def index
>>   pre = Array.new
>>   render :partial=>'index', :layout=>false, :locals=>{:pre=>pre}
>> end
>>
>> My controller spec
>> before do
>>   @controller = MyController.new
>> end
>> it "should render the index partial" do
>>   @controller.expect_render(:partial=>'index', :layout=>false) #I
>> don't
>> know how to expect the :locals
>> end
>>
>> As I mentioned, the spec failed , saying that "Undefined method
>> 'expect_render' ". There might be some mistakes in my "before" block. Do
>> I
>> need to mock the controller or something else? Anyway, do any one know
>> how
>> to fix the problem? It will be even better if you guys could show me a
>> piece
>> of example code.
>> Thanks!!
> 
> Have you looked here?
> 
> http://rspec.rubyforge.org/documentation/rails/writing/views.html
> 
> (you must use template.expect_render)
> Or perhaps you're looking for response.should
> render_template("path/to/template/for/action")
> 
> HTH,
> Aslak
> 
>> --
>> View this message in context:
>> http://www.nabble.com/How-to-use-expect_render--tf4259590.html#a12121894
>> Sent from the rspec-users mailing list archive at Nabble.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
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-use-expect_render--tf4259590.html#a12122511
Sent from the rspec-users mailing list archive at Nabble.com.

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


Re: [rspec-users] How to use expect_render?

2007-08-13 Thread Shaker

Dear Aslak and David:
I have tried two possible ways to get expect_render work. However, they
all failed. My combinations are:
my controller spec
  describe MyController do
before do
  #do nothing
end
it "should render the index partial" do
  controller.expect_render(:partial=>'index') #1st way
  MyController.expect_render(:partial=>'index') #2nd way
end
  end

The 1st way gave me an error: Mock 'expect_render_mock_proxy' expected
:render with ({:partial=>'index'}) once, but received it 0 times
The 2nd way gave me an error: undefined method 'expect_render'
Do I need to mock the controller or there are some mistakes I have made in
my spec?

Shaker wrote:
> 
> Hi:
> I am a rspec beginner. I have scratched my head for the whole
> afternoon, trying to figure out a way of writing render expectation in
> controller spec. However, I failed. It kept telling me that the
> 'expect_render' was an undefined method. I have installed rspec 1.0.8 and
> rspec_on_rails as well. Below is the controller to be tested. 
> 
> Controller
> def index
>   pre = Array.new
>   render :partial=>'index', :layout=>false, :locals=>{:pre=>pre} 
> end
> 
> My controller spec
> before do
>   @controller = MyController.new
> end
> it "should render the index partial" do
>   @controller.expect_render(:partial=>'index', :layout=>false) #I
> don't know how to expect the :locals
> end
> 
> As I mentioned, the spec failed , saying that "Undefined method
> 'expect_render' ". There might be some mistakes in my "before" block. Do I
> need to mock the controller or something else? Anyway, do any one know how
> to fix the problem? It will be even better if you guys could show me a
> piece of example code. 
> Thanks!!
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-use-expect_render--tf4259590.html#a12123224
Sent from the rspec-users mailing list archive at Nabble.com.

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


Re: [rspec-users] How to use expect_render?

2007-08-13 Thread Shaker

Dear Aslak:
Sorry to bother you over and over again. I did follow your instruction to
write the controller spec, but...the thing is not getting better.:-(
I'd like to post my code again, hopefully you would figure it out.
My Controller
class MyController
  def index
pre = Array.new
render :partial=>'index', layout=>false, locals=>{:pre=>pre}
  end
end

My Controller spec
describe MyController do
  it "should render the index partial" do
controller.expect_render(:partial=>'index', :layout=>false)
get 'index'
  end
end

By the way, I am using JRuby rather than ruby. Hence my command to run the
spec above is
jruby --command spec spec/controllers/my_controller_spec.rb --format specdoc
It always gave me an error:Mock 'expect_render_mock_proxy' expected :render
with 
({:partial=>"index"}) once, but received it 0 times.
Is it because "expect_render" is not compatible with JRuby or I forgot to
mock something?
  Thanks a lot.
  Regards.

aslak hellesoy wrote:
> 
> On 8/13/07, Shaker <[EMAIL PROTECTED]> wrote:
>>
>> Dear Aslak and David:
>> I have tried two possible ways to get expect_render work. However,
>> they
>> all failed. My combinations are:
>> my controller spec
>>   describe MyController do
>> before do
>>   #do nothing
>> end
>> it "should render the index partial" do
>>   controller.expect_render(:partial=>'index') #1st way
> 
> That's the way to go
> 
>>   MyController.expect_render(:partial=>'index') #2nd way
>> end
>>   end
>>
>> The 1st way gave me an error: Mock 'expect_render_mock_proxy' expected
>> :render with ({:partial=>'index'}) once, but received it 0 times
> 
> You've forgotten to run the action. RSpec doesn't magically guess what
> action is supposed to render your index partial.
> 
> it "should render the index partial" do
>   controller.expect_render(:partial=>'index')
>   get 'index'
> end
> 
> 
>> The 2nd way gave me an error: undefined method 'expect_render'
>> Do I need to mock the controller or there are some mistakes I have made
>> in
>> my spec?
>>
>> Shaker wrote:
>> >
>> > Hi:
>> > I am a rspec beginner. I have scratched my head for the whole
>> > afternoon, trying to figure out a way of writing render expectation in
>> > controller spec. However, I failed. It kept telling me that the
>> > 'expect_render' was an undefined method. I have installed rspec 1.0.8
>> and
>> > rspec_on_rails as well. Below is the controller to be tested.
>> >
>> > Controller
>> > def index
>> >   pre = Array.new
>> >   render :partial=>'index', :layout=>false, :locals=>{:pre=>pre}
>> > end
>> >
>> > My controller spec
>> > before do
>> >   @controller = MyController.new
>> > end
>> > it "should render the index partial" do
>> >   @controller.expect_render(:partial=>'index', :layout=>false) #I
>> > don't know how to expect the :locals
>> > end
>> >
>> > As I mentioned, the spec failed , saying that "Undefined method
>> > 'expect_render' ". There might be some mistakes in my "before" block.
>> Do I
>> > need to mock the controller or something else? Anyway, do any one know
>> how
>> > to fix the problem? It will be even better if you guys could show me a
>> > piece of example code.
>> > Thanks!!
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/How-to-use-expect_render--tf4259590.html#a12123224
>> Sent from the rspec-users mailing list archive at Nabble.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
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-use-expect_render--tf4259590.html#a12136984
Sent from the rspec-users mailing list archive at Nabble.com.

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


[rspec-users] Can Rspec do module spec? What if module uses test data?

2007-08-21 Thread Shaker

Dear fellows:
I am currently working on writing specs on some ruby modules(e.g.
myModule). At first I try to use script/generate to generate rspec_module,
but it failed. :-(
Later I manually created a file (e.g. named myModule_spec.rb) and put
the 'require spec_helper.rb' as the first line of code followed by
'describe' block. Luckily, it seemed to be working. But it was not likely to
be a logical way to generate module specs.
Question 1:Is there any better way of creating module spec??:confused:
Anyway, I started to write method specs in these manually created module
specs, and I found another problem. Module specs do not support 'fixtures'.
This means that if you test some methods which modify test data in your
module specs, that data won't be restored after you finish running each
spec. In other words, all the modules specs actually share a copy of test
data. This will cause some module specs to fail if other modules do modified
the shared data beforehand.
Question 2:What should I do to resolve this problem, making module specs
access test data independently? :confused:
-- 
View this message in context: 
http://www.nabble.com/Can-Rspec-do-module-spec--What-if-module-uses-test-data--tf4309226.html#a12267615
Sent from the rspec-users mailing list archive at Nabble.com.

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


[rspec-users] Can module spec use fixtures?

2007-08-22 Thread Shaker

Good morning, dear fellows:
I'd like to recall one question I posted yesterday. I am writing specs
for ruby modules. Some of the modules do some data process in the test
database. Because 'fixtures' is undefined (Am I correct?) in module specs,
spec of certain module (e.g. delete data form database) will affect other
specs of other modules (e.g. try to access the deleted data). My observation
is all the modules specs share only a copy of test data. 
If I am correct, are there any way of avoiding this, and providing a
copy of initial test data (like fixtures do) for each module spec?
Thanks
Regards.
-- 
View this message in context: 
http://www.nabble.com/Can-module-spec-use-fixtures--tf4314808.html#a12285512
Sent from the rspec-users mailing list archive at Nabble.com.

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


[rspec-users] Can module spec "behave like" controller spec?

2007-08-31 Thread Shaker

Hello everyone:
Right now I am writing spec on modules, which are provided by my
colleagues. Some of the modules actually contain action methods. I tried
very hard to spec those action methods in modules. But it seems that  the
rspec does not allow module spec to 'get' action like controller does. After
I saw the documentation, I then used :behaviour_type=>:controller. However,
it failed again. It reported an error for me. For illustration, I'd like a
simple example.
module MyModule
def copy #an action method
render :partial=>"/index", :layout=>false
end
end

describe MyModule, :behaviour_type=>:controller do
it "should render partial index" do
get 'copy' #test code not provided yet, just want to get the action
end
end
The error reported was: undefined method 'new' for MyModule:Module. Do you
guys have any idea of the error? And how should I test the action methods in
modules?
Cheers!


-- 
View this message in context: 
http://www.nabble.com/Can-module-spec-%22behave-like%22-controller-spec--tf4358891.html#a12422548
Sent from the rspec-users mailing list archive at Nabble.com.

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


[rspec-users] How to test 'Paginate'?

2007-09-10 Thread Shaker

Great Hi to everyone:
I don't know how to write spec for a controller method which has
'paginate'. Is there any Rspec API for it?
To illustrate, I would like to post an example.
class PeopleController
  def  paginate_method
hash = Hash.new
hash[:people_page], hash[:people] = paginate :people, ...#order and
conditions omitted
render :partial=>"/index", :layout=>false, :locals=>{:hash=>hash}
  end
end
  Does anyone who knows how to write spec on this method? I appreciate any
help. Thank you. 
-- 
View this message in context: 
http://www.nabble.com/How-to-test-%27Paginate%27--tf4420350.html#a12608257
Sent from the rspec-users mailing list archive at Nabble.com.

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


[rspec-users] Can not

2007-09-12 Thread Shaker


-- 
View this message in context: 
http://www.nabble.com/Can-not-tf4427918.html#a12631491
Sent from the rspec-users mailing list archive at Nabble.com.

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


[rspec-users] Can not 'assigns' value in View test

2007-09-12 Thread Shaker

Hello everyone:
  I am quit new to View test using rspec. I want to write spec for a
partial, which is rendered by a controller. However, the controller does not
pass data to the partial using instance variables, it uses symbol variable
instead. I read the example of view spec provided in the website. But the
example is using instance variable. So I am looking for a way of assigning
my test data to the partial to be tested. I would like to show an my code
below:
class MyController
  def index
hash = {...#data provided here}
render :partial=>'index', :layout=>false, :locals=>{:hash=>hash}
  end
end

_index.rhtml
  ..#unrelated code omitted
  
var data = <%= hash %>;

  

In my spec, I used assigns[:hash] = my_own_data, but an error occurred,
saying that "undefined local variable or method 'hash' ".
How can I assign my own data to hash in my view spec?
Thank you!

-- 
View this message in context: 
http://www.nabble.com/Can-not-%27assigns%27-value-in-View-test-tf4428018.html#a12631788
Sent from the rspec-users mailing list archive at Nabble.com.

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


Re: [rspec-users] Can not 'assigns' value in View test

2007-09-12 Thread Shaker

Unfortunately, I am not supposed to change the code inside the partial.
That's why I posted this message. I am trying to find a way of tackling this
problem. Because I am going to test tens of hundreds of partials, most of
which are using the symbols rather than instance variable. 

David Chelimsky-2 wrote:
> 
> On 9/12/07, Evan David Light <[EMAIL PROTECTED]> wrote:
>> Granted that I'm new too; however, assigns[:hash] creates a
>> member
>> variable @hash that is made available to the view.  Maybe that's the
>> problem?  Modify your view to use @hash instead.
> 
> http://rspec.rubyforge.org/documentation/rails/writing/views.html
> 
>>
>> On Sep 12, 2007, at 5:20 AM, Shaker wrote:
>>
>> >
>> > Hello everyone:
>> >   I am quit new to View test using rspec. I want to write spec for a
>> > partial, which is rendered by a controller. However, the controller
>> > does not
>> > pass data to the partial using instance variables, it uses symbol
>> > variable
>> > instead. I read the example of view spec provided in the website.
>> > But the
>> > example is using instance variable. So I am looking for a way of
>> > assigning
>> > my test data to the partial to be tested. I would like to show an
>> > my code
>> > below:
>> > class MyController
>> >   def index
>> > hash = {...#data provided here}
>> > render :partial=>'index', :layout=>false, :locals=>{:hash=>hash}
>> >   end
>> > end
>> >
>> > _index.rhtml
>> >   ..#unrelated code omitted
>> >   
>> > var data = <%= hash %>;
>> > <!-- process data here -->
>> >   
>> >
>> > In my spec, I used assigns[:hash] = my_own_data, but an error
>> > occurred,
>> > saying that "undefined local variable or method 'hash' ".
>> > How can I assign my own data to hash in my view spec?
>> > Thank you!
>> >
>> > --
>> > View this message in context: http://www.nabble.com/Can-not-%
>> > 27assigns%27-value-in-View-test-tf4428018.html#a12631788
>> > Sent from the rspec-users mailing list archive at Nabble.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
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Can-not-%27assigns%27-value-in-View-test-tf4428018.html#a12646459
Sent from the rspec-users mailing list archive at Nabble.com.

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


Re: [rspec-users] Can not 'assigns' value in View test

2007-09-12 Thread Shaker

I also feel puzzled. But that's what my colleagues do, and it works. The
thing is they use
  render :partial=>'index', :locals=>{:hash=>hash}
in the controller to pass the hash data to the partial it will render(index
in this case). And later they simply use <%= hash %> to get the hash data
passed from the controller. Maybe the :locals does some magical work here. I
am quite familiar with rspec and ruby. So I am reading more documentation
now.
Hopefully we could figure it out shortly.

David Chelimsky-2 wrote:
> 
> On 9/12/07, Shaker <[EMAIL PROTECTED]> wrote:
>>
>> Unfortunately, I am not supposed to change the code inside the partial.
>> That's why I posted this message. I am trying to find a way of tackling
>> this
>> problem. Because I am going to test tens of hundreds of partials, most of
>> which are using the symbols rather than instance variable.
> 
> Huh? Symbols in the partials that are supposed to magically transform
> to some value? I don't get it. What am I missing?
> 
>>
>> David Chelimsky-2 wrote:
>> >
>> > On 9/12/07, Evan David Light <[EMAIL PROTECTED]> wrote:
>> >> Granted that I'm new too; however, assigns[:hash] creates a
>> >> member
>> >> variable @hash that is made available to the view.  Maybe that's the
>> >> problem?  Modify your view to use @hash instead.
>> >
>> > http://rspec.rubyforge.org/documentation/rails/writing/views.html
>> >
>> >>
>> >> On Sep 12, 2007, at 5:20 AM, Shaker wrote:
>> >>
>> >> >
>> >> > Hello everyone:
>> >> >   I am quit new to View test using rspec. I want to write spec for a
>> >> > partial, which is rendered by a controller. However, the controller
>> >> > does not
>> >> > pass data to the partial using instance variables, it uses symbol
>> >> > variable
>> >> > instead. I read the example of view spec provided in the website.
>> >> > But the
>> >> > example is using instance variable. So I am looking for a way of
>> >> > assigning
>> >> > my test data to the partial to be tested. I would like to show an
>> >> > my code
>> >> > below:
>> >> > class MyController
>> >> >   def index
>> >> > hash = {...#data provided here}
>> >> > render :partial=>'index', :layout=>false, :locals=>{:hash=>hash}
>> >> >   end
>> >> > end
>> >> >
>> >> > _index.rhtml
>> >> >   ..#unrelated code omitted
>> >> >   
>> >> > var data = <%= hash %>;
>> >> > <!-- process data here -->
>> >> >   
>> >> >
>> >> > In my spec, I used assigns[:hash] = my_own_data, but an error
>> >> > occurred,
>> >> > saying that "undefined local variable or method 'hash' ".
>> >> > How can I assign my own data to hash in my view spec?
>> >> > Thank you!
>> >> >
>> >> > --
>> >> > View this message in context: http://www.nabble.com/Can-not-%
>> >> > 27assigns%27-value-in-View-test-tf4428018.html#a12631788
>> >> > Sent from the rspec-users mailing list archive at Nabble.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
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Can-not-%27assigns%27-value-in-View-test-tf4428018.html#a12646459
>> Sent from the rspec-users mailing list archive at Nabble.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
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Can-not-%27assigns%27-value-in-View-test-tf4428018.html#a12646774
Sent from the rspec-users mailing list archive at Nabble.com.

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


Re: [rspec-users] Can not 'assigns' value in View test

2007-09-12 Thread Shaker

Hello, David:
  Thank you very much for your help. Now it works! 
  I would like to recall a message posted several days ago regarding the
"paginate". How to test "paginate" in controller spec? One simple example
may be like this:
  hash[:accounts_pages], hash[:accounts] = paginate :accounts(the table),
#order and conditions follows
How should I test this code in controller spec? Or can I mock this line,
like should_receive(:paginate).and_return(...)? But the problem is
'paginate' returns two values. :(
  Thanks for investigating this question.

David Chelimsky-2 wrote:
> 
> On 9/12/07, Shaker <[EMAIL PROTECTED]> wrote:
>>
>> I also feel puzzled. But that's what my colleagues do, and it works. The
>> thing is they use
>>   render :partial=>'index', :locals=>{:hash=>hash}
>> in the controller to pass the hash data to the partial it will
>> render(index
>> in this case). And later they simply use <%= hash %> to get the hash data
>> passed from the controller.
> 
> Now THAT is a horse of a different color. OK - first:
> 
>   render :partial=>'index', :locals=>{:hash=>hash}
> 
> Here, the symbol :hash is just a key - it is not the object that's
> been passed around.
> 
> Second:
> 
>   <%= hash %>
> 
> I'm assuming that's in the partial named index (a partial named
> index???, now THAT's not at all confusing). In this case, the
> :locals => {:hash=>hash} in the calling template assigns the hash
> object (in the calling template's scope) as the return value of a
> method in the partial named  (drum roll, please)  hash. Like
> hash().
> 
> So - what you want to do is to stub the hash method on the template:
> 
>  
> template.stub!(:hash).and_return(the_hash_I_want_to_stick_in_the_template)
> 
> That all make sense?
> 
> Good luck!
> 
>> Maybe the :locals does some magical work here. I
>> am quite familiar with rspec and ruby. So I am reading more documentation
>> now.
>> Hopefully we could figure it out shortly.
>>
>> David Chelimsky-2 wrote:
>> >
>> > On 9/12/07, Shaker <[EMAIL PROTECTED]> wrote:
>> >>
>> >> Unfortunately, I am not supposed to change the code inside the
>> partial.
>> >> That's why I posted this message. I am trying to find a way of
>> tackling
>> >> this
>> >> problem. Because I am going to test tens of hundreds of partials, most
>> of
>> >> which are using the symbols rather than instance variable.
>> >
>> > Huh? Symbols in the partials that are supposed to magically transform
>> > to some value? I don't get it. What am I missing?
>> >
>> >>
>> >> David Chelimsky-2 wrote:
>> >> >
>> >> > On 9/12/07, Evan David Light <[EMAIL PROTECTED]> wrote:
>> >> >> Granted that I'm new too; however, assigns[:hash] creates a
>> >> >> member
>> >> >> variable @hash that is made available to the view.  Maybe that's
>> the
>> >> >> problem?  Modify your view to use @hash instead.
>> >> >
>> >> > http://rspec.rubyforge.org/documentation/rails/writing/views.html
>> >> >
>> >> >>
>> >> >> On Sep 12, 2007, at 5:20 AM, Shaker wrote:
>> >> >>
>> >> >> >
>> >> >> > Hello everyone:
>> >> >> >   I am quit new to View test using rspec. I want to write spec
>> for a
>> >> >> > partial, which is rendered by a controller. However, the
>> controller
>> >> >> > does not
>> >> >> > pass data to the partial using instance variables, it uses symbol
>> >> >> > variable
>> >> >> > instead. I read the example of view spec provided in the website.
>> >> >> > But the
>> >> >> > example is using instance variable. So I am looking for a way of
>> >> >> > assigning
>> >> >> > my test data to the partial to be tested. I would like to show an
>> >> >> > my code
>> >> >> > below:
>> >> >> > class MyController
>> >> >> >   def index
>> >> >> > hash = {...#data provided here}
>> >> >> > render :partial=>'index', :layout=>false,
>> :locals=>{:hash=>h

[rspec-users] Need help in View Spec

2007-09-13 Thread Shaker

Hello everyone:
  I am kind of puzzled in writing spec on view partials. I can not find much
information about the "should have_tag" syntax in Rspec. Can rspec test a
particular attribute of a tag (e.g. input tag)? Let me put an example here:
#../view/group/_index
  

  
I want to test the "onclick" attribute in the input tag, which ensure that
clicking the button will call the correct Javascript method. How should I
do?
  Great thanks for any help.
-- 
View this message in context: 
http://www.nabble.com/Need-help-in-View-Spec-tf4439760.html#a12667395
Sent from the rspec-users mailing list archive at Nabble.com.

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


Re: [rspec-users] Need help in View Spec

2007-09-13 Thread Shaker

Yes, I have gone through the documentation before, and I read the reference
of 'assert_select' as well. But I still can not figure out a way of testing
attributes in a tag. What I know is we can use:
  should have_tag("tag#id") or should have_tag("tag.class")
to select a tag, whereas I don't know how to select an attribute and test
it!
Another problem is the tag does not have id or class sometimes, does it mean
that is no way of selecting it?

David Chelimsky-2 wrote:
> 
> On 9/13/07, Shaker <[EMAIL PROTECTED]> wrote:
>> I can not find much
>> information about the "should have_tag" syntax in Rspec.
> 
> http://rspec.rubyforge.org/rdoc-rails/classes/Spec/Rails/Matchers.html#M11
> ___
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Need-help-in-View-Spec-tf4439760.html#a12667582
Sent from the rspec-users mailing list archive at Nabble.com.

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


Re: [rspec-users] Need help in View Spec

2007-09-13 Thread Shaker

Sorry, that's another spec caused the error. It is working. Thank you very
much

Shaker wrote:
> 
> Hello
>   To spec the example I mentioned before, I wrote the spec as what you
> suggested
> #../view/group/index_spec.rb
>   describe "/group/_index_spec" do
> it "should call JS function when click the button" do
>   render '/group/_index'
>   response.should have_tag("input[onclick=?]", "update()")
> end
>   end
> However, it generated an error "Expecting a selector as the first
> argument". What is wrong?
> 
> David Chelimsky-2 wrote:
>> 
>> On 9/13/07, Shaker <[EMAIL PROTECTED]> wrote:
>>>
>>> Yes, I have gone through the documentation before, and I read the
>>> reference
>>> of 'assert_select' as well. But I still can not figure out a way of
>>> testing
>>> attributes in a tag. What I know is we can use:
>>>   should have_tag("tag#id") or should have_tag("tag.class")
>>> to select a tag, whereas I don't know how to select an attribute and
>>> test
>>> it!
>> 
>> That's all covered in the assert_select docs. Here's a cheat sheet you
>> might find useful.
>> 
>> http://labnotes.org/svn/public/ruby/rails_plugins/assert_select/cheat/assert_select.html
>> 
>> so you can do this:
>> 
>> response.should have_tag("form[action=?][method=post]", foo_path(@foo))
>> 
>> HTH
>> 
>> 
>> 
>> 
>> 
>>> Another problem is the tag does not have id or class sometimes, does it
>>> mean
>>> that is no way of selecting it?
>>>
>>> David Chelimsky-2 wrote:
>>> >
>>> > On 9/13/07, Shaker <[EMAIL PROTECTED]> wrote:
>>> >> I can not find much
>>> >> information about the "should have_tag" syntax in Rspec.
>>> >
>>> >
>>> http://rspec.rubyforge.org/rdoc-rails/classes/Spec/Rails/Matchers.html#M11
>>> > ___
>>> > rspec-users mailing list
>>> > rspec-users@rubyforge.org
>>> > http://rubyforge.org/mailman/listinfo/rspec-users
>>> >
>>> >
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Need-help-in-View-Spec-tf4439760.html#a12667582
>>> Sent from the rspec-users mailing list archive at Nabble.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
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Need-help-in-View-Spec-tf4439760.html#a12667734
Sent from the rspec-users mailing list archive at Nabble.com.

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


Re: [rspec-users] Need help in View Spec

2007-09-13 Thread Shaker

Hello
  To spec the example I mentioned before, I wrote the spec as what you
suggested
#../view/group/index_spec.rb
  describe "/group/_index_spec" do
it "should call JS function when click the button" do
  render '/group/_index'
  response.should have_tag("input[onclick=?]", "update()")
end
  end
However, it generated an error "Expecting a selector as the first argument".
What is wrong?

David Chelimsky-2 wrote:
> 
> On 9/13/07, Shaker <[EMAIL PROTECTED]> wrote:
>>
>> Yes, I have gone through the documentation before, and I read the
>> reference
>> of 'assert_select' as well. But I still can not figure out a way of
>> testing
>> attributes in a tag. What I know is we can use:
>>   should have_tag("tag#id") or should have_tag("tag.class")
>> to select a tag, whereas I don't know how to select an attribute and test
>> it!
> 
> That's all covered in the assert_select docs. Here's a cheat sheet you
> might find useful.
> 
> http://labnotes.org/svn/public/ruby/rails_plugins/assert_select/cheat/assert_select.html
> 
> so you can do this:
> 
> response.should have_tag("form[action=?][method=post]", foo_path(@foo))
> 
> HTH
> 
> 
> 
> 
> 
>> Another problem is the tag does not have id or class sometimes, does it
>> mean
>> that is no way of selecting it?
>>
>> David Chelimsky-2 wrote:
>> >
>> > On 9/13/07, Shaker <[EMAIL PROTECTED]> wrote:
>> >> I can not find much
>> >> information about the "should have_tag" syntax in Rspec.
>> >
>> >
>> http://rspec.rubyforge.org/rdoc-rails/classes/Spec/Rails/Matchers.html#M11
>> > ___
>> > rspec-users mailing list
>> > rspec-users@rubyforge.org
>> > http://rubyforge.org/mailman/listinfo/rspec-users
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Need-help-in-View-Spec-tf4439760.html#a12667582
>> Sent from the rspec-users mailing list archive at Nabble.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
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Need-help-in-View-Spec-tf4439760.html#a12667709
Sent from the rspec-users mailing list archive at Nabble.com.

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


[rspec-users] Is Rcov working with Jruby now?

2007-09-23 Thread Shaker

Hello everyone:
  I am currently assigned to test a big project which uses JRuby to build a
web application. The reason of using JRuby is the web application is
communicating with Java Service. I am writing test cases using Rspec and
looking for a code coverage tool. Rcov is no doubt a nice code coverage
tool. However, it is said that Rcov is not compatible with JRuby so far.
SighI can not find any other code coverage tools for JRuby. Some
developers are working on this problem. So I am wondering whether there are
any progresses so far? Or are there any alternative code coverage tools for
JRuby?  
-- 
View this message in context: 
http://www.nabble.com/Is-Rcov-working-with-Jruby-now--tf4506880.html#a12853457
Sent from the rspec-users mailing list archive at Nabble.com.

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


[rspec-users] weird behavior of mocking ruby class methods

2007-12-06 Thread Shaker

Hello everyone:
  After I played with Rspec for three months, I realized a weird behavior of
mocking ruby classes (e.g. File).
  Please let me post a sample code before I point out the problems:
  #file_reader.rb (to be tested)
  class FileReader
def do_read
  File.read('asd.txt')
end
  end
  #file_reader_spec.rb
  describe FileReader, "do_read" do
it "should throw File Not Found on non-existent file" do
  reader = FileReader.new()
  lambda { 
reader.do_read
  }.should raise_error(Errno::ENOENT)
end
  end
  describe FileReader, "do_read" do
it "should read the mock contents" do
  reader = FileReader.new()
  File.should_receive(:read).and_return('file contents')
  reader.do_read.should == 'file contents'
end
  end
In the test cases shown above, I wanted to mock the "read" method in ruby
"File" class.
The first case passed while the second one failed. I suspected that the
mocking was not working in the second case. (Please see the output in
"Scenario 1" in the attached file)
Then I switched the running order of the test cases, another interesting
result came out. The mocking worked well this time but "read" method in
"File" class became undefined in the second test case. It seemed that the
mocking erased the "read" method. (Please see the output in "Scenario 2" in
the attached file)
http://www.nabble.com/file/p14205880/result.txt result.txt 
I am wondering what is going on out there when I mocked a method of ruby
class? 
Do I use mocking in a proper way as the sample code shown above? 
What is the correct way of mocking methods of ruby classes?
-- 
View this message in context: 
http://www.nabble.com/weird-behavior-of-mocking-ruby-class-methods-tf4959949.html#a14205880
Sent from the rspec-users mailing list archive at Nabble.com.

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