Hello, Has anyone already come up with a set of shared behaviours that someone could leverage when adhering to a CRUD concept, with respect to controllers? Relatedly, it would be nice if there were a way to share generalized behaviour specs. -Chris
On 5/4/07, Chris Hoffman <chris.c.hoffman at gmail.com> wrote:> Hello, > > Has anyone already come up with a set of shared behaviours that > someone could leverage when adhering to a CRUD concept, with respect > to controllers? > > Relatedly, it would be nice if there were a way to share generalized > behaviour specs.Shared behaviours already allow you to do this, unless I''m missing your meaning. What is it that you''re looking for that shared behaviours as/is doesn''t cover?> > -Chris > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Oh there is nothing wrong with the code, I just wonder if anyone has actually taken it further and implemented the behaviours required to exercise the CRUD operations in controllers (e.g., #show, #new, #edit, etc.). And as to sharing, I mean in a colloquial way, as in collaboration. -Chris On 5/4/07, David Chelimsky <dchelimsky at gmail.com> wrote:> On 5/4/07, Chris Hoffman <chris.c.hoffman at gmail.com> wrote: > > Hello, > > > > Has anyone already come up with a set of shared behaviours that > > someone could leverage when adhering to a CRUD concept, with respect > > to controllers? > > > > Relatedly, it would be nice if there were a way to share generalized > > behaviour specs. > > Shared behaviours already allow you to do this, unless I''m missing > your meaning. What is it that you''re looking for that shared > behaviours as/is doesn''t cover? > > > > > -Chris > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On 5/4/07, Chris Hoffman <chris.c.hoffman at gmail.com> wrote:> Oh there is nothing wrong with the code, I just wonder if anyone has > actually taken it further and implemented the behaviours required to > exercise the CRUD operations in controllers (e.g., #show, #new, #edit, > etc.).I understood that part - that you wanted to see if someone had tackled the problem.> > And as to sharing, I mean in a colloquial way, as in collaboration.This was the part I was talking about, and now I get it. Besides posting code on blogs, what would you propose to better enable this so that anybody who wants to contribute can, but everyone keeps control over their own contributions? Cheers, David> > -Chris > > On 5/4/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > On 5/4/07, Chris Hoffman <chris.c.hoffman at gmail.com> wrote: > > > Hello, > > > > > > Has anyone already come up with a set of shared behaviours that > > > someone could leverage when adhering to a CRUD concept, with respect > > > to controllers? > > > > > > Relatedly, it would be nice if there were a way to share generalized > > > behaviour specs. > > > > Shared behaviours already allow you to do this, unless I''m missing > > your meaning. What is it that you''re looking for that shared > > behaviours as/is doesn''t cover? > > > > > > > > -Chris > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Well, I guess posting code on blogs is fine, as long as there is a centralized way of accessing this code. Perhaps some kind of aggregator would suffice? I don''t know if sites like technorati or del.icio.us can help in this respect. My initial thought was a wiki, but if you think people will want to control their own contributions, than obviously this is a poor idea. -Chris On 5/4/07, David Chelimsky <dchelimsky at gmail.com> wrote:> On 5/4/07, Chris Hoffman <chris.c.hoffman at gmail.com> wrote: > > Oh there is nothing wrong with the code, I just wonder if anyone has > > actually taken it further and implemented the behaviours required to > > exercise the CRUD operations in controllers (e.g., #show, #new, #edit, > > etc.). > > I understood that part - that you wanted to see if someone had tackled > the problem. > > > > > And as to sharing, I mean in a colloquial way, as in collaboration. > > This was the part I was talking about, and now I get it. Besides > posting code on blogs, what would you propose to better enable this so > that anybody who wants to contribute can, but everyone keeps control > over their own contributions? > > Cheers, > David > > > > > -Chris > > > > On 5/4/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > On 5/4/07, Chris Hoffman <chris.c.hoffman at gmail.com> wrote: > > > > Hello, > > > > > > > > Has anyone already come up with a set of shared behaviours that > > > > someone could leverage when adhering to a CRUD concept, with respect > > > > to controllers? > > > > > > > > Relatedly, it would be nice if there were a way to share generalized > > > > behaviour specs. > > > > > > Shared behaviours already allow you to do this, unless I''m missing > > > your meaning. What is it that you''re looking for that shared > > > behaviours as/is doesn''t cover? > > > > > > > > > > > -Chris > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Hello, So, here is my first stab at generalized CRUD behaviours. I would appreciate your thoughts on my approach. Be gentle :) describe "RUD", :shared => true do before(:each) do @model = @controller_class.to_s.sub(/Controller$/,'''').singularize.constantize @obj = mock_model(@model) end it "should populate the object related to the model when given a valid id" do @model.should_receive(:find_by_id).with(''1'').and_return(@obj) get @action, :id => 1 assigns[@model.to_s.underscore].should be(@obj) end it "should redirect_to #index when given an invalid id" do @model.should_receive(:find_by_id) get @action response.should redirect_to(:action => ''index'') end it "should populate the flash with a message indicating that the record wasn''t found, when given an invalid id" do @model.should_receive(:find_by_id) process @action flash[:notice].should == "#{@model} not found" end end describe "R", :shared => true do it "should render the appropriate template when given a valid id" do @model.should_receive(:find_by_id).and_return(@obj) get @action response.should render_template(@action) end it_should_behave_like "RUD" end describe "show", :shared => true do before(:each) do @action = "show" end it_should_behave_like "R" end On 5/4/07, Chris Hoffman <chris.c.hoffman at gmail.com> wrote:> Well, I guess posting code on blogs is fine, as long as there is a > centralized way of accessing this code. Perhaps some kind of > aggregator would suffice? I don''t know if sites like technorati or > del.icio.us can help in this respect. > > My initial thought was a wiki, but if you think people will want to > control their own contributions, than obviously this is a poor idea. > > -Chris > > On 5/4/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > On 5/4/07, Chris Hoffman <chris.c.hoffman at gmail.com> wrote: > > > Oh there is nothing wrong with the code, I just wonder if anyone has > > > actually taken it further and implemented the behaviours required to > > > exercise the CRUD operations in controllers (e.g., #show, #new, #edit, > > > etc.). > > > > I understood that part - that you wanted to see if someone had tackled > > the problem. > > > > > > > > And as to sharing, I mean in a colloquial way, as in collaboration. > > > > This was the part I was talking about, and now I get it. Besides > > posting code on blogs, what would you propose to better enable this so > > that anybody who wants to contribute can, but everyone keeps control > > over their own contributions? > > > > Cheers, > > David > > > > > > > > -Chris > > > > > > On 5/4/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > > > On 5/4/07, Chris Hoffman <chris.c.hoffman at gmail.com> wrote: > > > > > Hello, > > > > > > > > > > Has anyone already come up with a set of shared behaviours that > > > > > someone could leverage when adhering to a CRUD concept, with respect > > > > > to controllers? > > > > > > > > > > Relatedly, it would be nice if there were a way to share generalized > > > > > behaviour specs. > > > > > > > > Shared behaviours already allow you to do this, unless I''m missing > > > > your meaning. What is it that you''re looking for that shared > > > > behaviours as/is doesn''t cover? > > > > > > > > > > > > > > -Chris > > > > > _______________________________________________ > > > > > rspec-users mailing list > > > > > rspec-users at rubyforge.org > > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > > > _______________________________________________ > > > > rspec-users mailing list > > > > rspec-users at rubyforge.org > > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > >
Hi Chris, Looks good mate. Is there also a way of being able to get the name of the controller or some other variables into the ''it'' strings to make the verbalisations read well for shared specs? like: it "should assign #{@model.to_s.underscore} for the view....." do ... end and so on, I tried the above, but no go yet. Cheers, Marcus On 05/05/2007, at 5:17 AM, Chris Hoffman wrote:> Hello, > > So, here is my first stab at generalized CRUD behaviours. I would > appreciate your thoughts on my approach. Be gentle :) > > describe "RUD", :shared => true do > before(:each) do > @model = @controller_class.to_s.sub(/Controller > $/,'''').singularize.constantize > @obj = mock_model(@model) > end > > it "should populate the object related to the model when given a > valid id" do > @model.should_receive(:find_by_id).with(''1'').and_return(@obj) > get @action, :id => 1 > assigns[@model.to_s.underscore].should be(@obj) > end > > it "should redirect_to #index when given an invalid id" do > @model.should_receive(:find_by_id) > get @action > response.should redirect_to(:action => ''index'') > end > > it "should populate the flash with a message indicating that the > record wasn''t found, when given an invalid id" do > @model.should_receive(:find_by_id) > process @action > flash[:notice].should == "#{@model} not found" > end > end > > describe "R", :shared => true do > it "should render the appropriate template when given a valid id" do > @model.should_receive(:find_by_id).and_return(@obj) > get @action > response.should render_template(@action) > end > > it_should_behave_like "RUD" > end > > describe "show", :shared => true do > before(:each) do > @action = "show" > end > > it_should_behave_like "R" > end > > On 5/4/07, Chris Hoffman <chris.c.hoffman at gmail.com> wrote: >> Well, I guess posting code on blogs is fine, as long as there is a >> centralized way of accessing this code. Perhaps some kind of >> aggregator would suffice? I don''t know if sites like technorati or >> del.icio.us can help in this respect. >> >> My initial thought was a wiki, but if you think people will want to >> control their own contributions, than obviously this is a poor idea. >> >> -Chris >> >> On 5/4/07, David Chelimsky <dchelimsky at gmail.com> wrote: >>> On 5/4/07, Chris Hoffman <chris.c.hoffman at gmail.com> wrote: >>>> Oh there is nothing wrong with the code, I just wonder if anyone >>>> has >>>> actually taken it further and implemented the behaviours >>>> required to >>>> exercise the CRUD operations in controllers (e.g., #show, #new, >>>> #edit, >>>> etc.). >>> >>> I understood that part - that you wanted to see if someone had >>> tackled >>> the problem. >>> >>>> >>>> And as to sharing, I mean in a colloquial way, as in collaboration. >>> >>> This was the part I was talking about, and now I get it. Besides >>> posting code on blogs, what would you propose to better enable >>> this so >>> that anybody who wants to contribute can, but everyone keeps control >>> over their own contributions? >>> >>> Cheers, >>> David >>> >>>> >>>> -Chris >>>> >>>> On 5/4/07, David Chelimsky <dchelimsky at gmail.com> wrote: >>>>> On 5/4/07, Chris Hoffman <chris.c.hoffman at gmail.com> wrote: >>>>>> Hello, >>>>>> >>>>>> Has anyone already come up with a set of shared behaviours that >>>>>> someone could leverage when adhering to a CRUD concept, with >>>>>> respect >>>>>> to controllers? >>>>>> >>>>>> Relatedly, it would be nice if there were a way to share >>>>>> generalized >>>>>> behaviour specs. >>>>> >>>>> Shared behaviours already allow you to do this, unless I''m missing >>>>> your meaning. What is it that you''re looking for that shared >>>>> behaviours as/is doesn''t cover? >>>>> >>>>>> >>>>>> -Chris >>>>>> _______________________________________________ >>>>>> rspec-users mailing list >>>>>> rspec-users at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
On 5/4/07, Marcus Crafter <crafterm at gmail.com> wrote:> Hi Chris, > > Looks good mate. Is there also a way of being able to get the name of > the controller or some other variables into the ''it'' strings to make > the verbalisations read well for shared specs? > > like: > > it "should assign #{@model.to_s.underscore} for the view....." doHow about ... it "should assign #{@model.humanize} for the view....." do> ... > end > > and so on, I tried the above, but no go yet. > > Cheers, > > Marcus > > > On 05/05/2007, at 5:17 AM, Chris Hoffman wrote: > > > Hello, > > > > So, here is my first stab at generalized CRUD behaviours. I would > > appreciate your thoughts on my approach. Be gentle :) > > > > describe "RUD", :shared => true do > > before(:each) do > > @model = @controller_class.to_s.sub(/Controller > > $/,'''').singularize.constantize > > @obj = mock_model(@model) > > end > > > > it "should populate the object related to the model when given a > > valid id" do > > @model.should_receive(:find_by_id).with(''1'').and_return(@obj) > > get @action, :id => 1 > > assigns[@model.to_s.underscore].should be(@obj) > > end > > > > it "should redirect_to #index when given an invalid id" do > > @model.should_receive(:find_by_id) > > get @action > > response.should redirect_to(:action => ''index'') > > end > > > > it "should populate the flash with a message indicating that the > > record wasn''t found, when given an invalid id" do > > @model.should_receive(:find_by_id) > > process @action > > flash[:notice].should == "#{@model} not found" > > end > > end > > > > describe "R", :shared => true do > > it "should render the appropriate template when given a valid id" do > > @model.should_receive(:find_by_id).and_return(@obj) > > get @action > > response.should render_template(@action) > > end > > > > it_should_behave_like "RUD" > > end > > > > describe "show", :shared => true do > > before(:each) do > > @action = "show" > > end > > > > it_should_behave_like "R" > > end > > > > On 5/4/07, Chris Hoffman <chris.c.hoffman at gmail.com> wrote: > >> Well, I guess posting code on blogs is fine, as long as there is a > >> centralized way of accessing this code. Perhaps some kind of > >> aggregator would suffice? I don''t know if sites like technorati or > >> del.icio.us can help in this respect. > >> > >> My initial thought was a wiki, but if you think people will want to > >> control their own contributions, than obviously this is a poor idea. > >> > >> -Chris > >> > >> On 5/4/07, David Chelimsky <dchelimsky at gmail.com> wrote: > >>> On 5/4/07, Chris Hoffman <chris.c.hoffman at gmail.com> wrote: > >>>> Oh there is nothing wrong with the code, I just wonder if anyone > >>>> has > >>>> actually taken it further and implemented the behaviours > >>>> required to > >>>> exercise the CRUD operations in controllers (e.g., #show, #new, > >>>> #edit, > >>>> etc.). > >>> > >>> I understood that part - that you wanted to see if someone had > >>> tackled > >>> the problem. > >>> > >>>> > >>>> And as to sharing, I mean in a colloquial way, as in collaboration. > >>> > >>> This was the part I was talking about, and now I get it. Besides > >>> posting code on blogs, what would you propose to better enable > >>> this so > >>> that anybody who wants to contribute can, but everyone keeps control > >>> over their own contributions? > >>> > >>> Cheers, > >>> David > >>> > >>>> > >>>> -Chris > >>>> > >>>> On 5/4/07, David Chelimsky <dchelimsky at gmail.com> wrote: > >>>>> On 5/4/07, Chris Hoffman <chris.c.hoffman at gmail.com> wrote: > >>>>>> Hello, > >>>>>> > >>>>>> Has anyone already come up with a set of shared behaviours that > >>>>>> someone could leverage when adhering to a CRUD concept, with > >>>>>> respect > >>>>>> to controllers? > >>>>>> > >>>>>> Relatedly, it would be nice if there were a way to share > >>>>>> generalized > >>>>>> behaviour specs. > >>>>> > >>>>> Shared behaviours already allow you to do this, unless I''m missing > >>>>> your meaning. What is it that you''re looking for that shared > >>>>> behaviours as/is doesn''t cover? > >>>>> > >>>>>> > >>>>>> -Chris > >>>>>> _______________________________________________ > >>>>>> rspec-users mailing list > >>>>>> rspec-users at rubyforge.org > >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>>>> > >>>>> _______________________________________________ > >>>>> rspec-users mailing list > >>>>> rspec-users at rubyforge.org > >>>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>>> > >>>> _______________________________________________ > >>>> rspec-users mailing list > >>>> rspec-users at rubyforge.org > >>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>> > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >>> > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Hi Marcus, I couldn''t get variables into the descriptions, as they seem to get compiled (for lack of a better word) and are immutable when executed by other methods (via the ''it_should_behave_like'' method call). Perhaps someone that has more experience with this code base could figure something out. I''m also wondering if I am reinventing the wheel. Since DHH''s "World of Resources" talk, I have been out of the loop as far as the push towards CRUDy architecture. I wonder if something has already been done to address this repetition in Test:Unit, which could be translated to RSpec. It''s really too bad that RSpec isn''t the default "testing" framework in Rails. Anyway, enough preaching to the choir. -Chris On 5/4/07, Marcus Crafter <crafterm at gmail.com> wrote:> Hi Chris, > > Looks good mate. Is there also a way of being able to get the name of > the controller or some other variables into the ''it'' strings to make > the verbalisations read well for shared specs? > > like: > > it "should assign #{@model.to_s.underscore} for the view....." do > ... > end > > and so on, I tried the above, but no go yet. > > Cheers, > > Marcus > > > On 05/05/2007, at 5:17 AM, Chris Hoffman wrote: > > > Hello, > > > > So, here is my first stab at generalized CRUD behaviours. I would > > appreciate your thoughts on my approach. Be gentle :) > > > > describe "RUD", :shared => true do > > before(:each) do > > @model = @controller_class.to_s.sub(/Controller > > $/,'''').singularize.constantize > > @obj = mock_model(@model) > > end > > > > it "should populate the object related to the model when given a > > valid id" do > > @model.should_receive(:find_by_id).with(''1'').and_return(@obj) > > get @action, :id => 1 > > assigns[@model.to_s.underscore].should be(@obj) > > end > > > > it "should redirect_to #index when given an invalid id" do > > @model.should_receive(:find_by_id) > > get @action > > response.should redirect_to(:action => ''index'') > > end > > > > it "should populate the flash with a message indicating that the > > record wasn''t found, when given an invalid id" do > > @model.should_receive(:find_by_id) > > process @action > > flash[:notice].should == "#{@model} not found" > > end > > end > > > > describe "R", :shared => true do > > it "should render the appropriate template when given a valid id" do > > @model.should_receive(:find_by_id).and_return(@obj) > > get @action > > response.should render_template(@action) > > end > > > > it_should_behave_like "RUD" > > end > > > > describe "show", :shared => true do > > before(:each) do > > @action = "show" > > end > > > > it_should_behave_like "R" > > end > > > > On 5/4/07, Chris Hoffman <chris.c.hoffman at gmail.com> wrote: > >> Well, I guess posting code on blogs is fine, as long as there is a > >> centralized way of accessing this code. Perhaps some kind of > >> aggregator would suffice? I don''t know if sites like technorati or > >> del.icio.us can help in this respect. > >> > >> My initial thought was a wiki, but if you think people will want to > >> control their own contributions, than obviously this is a poor idea. > >> > >> -Chris > >> > >> On 5/4/07, David Chelimsky <dchelimsky at gmail.com> wrote: > >>> On 5/4/07, Chris Hoffman <chris.c.hoffman at gmail.com> wrote: > >>>> Oh there is nothing wrong with the code, I just wonder if anyone > >>>> has > >>>> actually taken it further and implemented the behaviours > >>>> required to > >>>> exercise the CRUD operations in controllers (e.g., #show, #new, > >>>> #edit, > >>>> etc.). > >>> > >>> I understood that part - that you wanted to see if someone had > >>> tackled > >>> the problem. > >>> > >>>> > >>>> And as to sharing, I mean in a colloquial way, as in collaboration. > >>> > >>> This was the part I was talking about, and now I get it. Besides > >>> posting code on blogs, what would you propose to better enable > >>> this so > >>> that anybody who wants to contribute can, but everyone keeps control > >>> over their own contributions? > >>> > >>> Cheers, > >>> David > >>> > >>>> > >>>> -Chris > >>>> > >>>> On 5/4/07, David Chelimsky <dchelimsky at gmail.com> wrote: > >>>>> On 5/4/07, Chris Hoffman <chris.c.hoffman at gmail.com> wrote: > >>>>>> Hello, > >>>>>> > >>>>>> Has anyone already come up with a set of shared behaviours that > >>>>>> someone could leverage when adhering to a CRUD concept, with > >>>>>> respect > >>>>>> to controllers? > >>>>>> > >>>>>> Relatedly, it would be nice if there were a way to share > >>>>>> generalized > >>>>>> behaviour specs. > >>>>> > >>>>> Shared behaviours already allow you to do this, unless I''m missing > >>>>> your meaning. What is it that you''re looking for that shared > >>>>> behaviours as/is doesn''t cover? > >>>>> > >>>>>> > >>>>>> -Chris > >>>>>> _______________________________________________ > >>>>>> rspec-users mailing list > >>>>>> rspec-users at rubyforge.org > >>>>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>>>> > >>>>> _______________________________________________ > >>>>> rspec-users mailing list > >>>>> rspec-users at rubyforge.org > >>>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>>> > >>>> _______________________________________________ > >>>> rspec-users mailing list > >>>> rspec-users at rubyforge.org > >>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>> > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >>> > >> > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Hi David, On 05/05/2007, at 12:59 PM, David Chelimsky wrote:> On 5/4/07, Marcus Crafter <crafterm at gmail.com> wrote: >> Hi Chris, >> >> Looks good mate. Is there also a way of being able to get the name of >> the controller or some other variables into the ''it'' strings to make >> the verbalisations read well for shared specs? >> >> like: >> >> it "should assign #{@model.to_s.underscore} for the view....." do > > How about ... > > it "should assign #{@model.humanize} for the view....." doMuch better and would be fine with me, but the variable replacement currently doesn''t resolve @model,etc at all unfortunately. Any thoughts where to look? Digging deeper.. Cheers, Marcus
On 5/5/07, Marcus Crafter <crafterm at gmail.com> wrote:> Hi David, > > On 05/05/2007, at 12:59 PM, David Chelimsky wrote: > > > On 5/4/07, Marcus Crafter <crafterm at gmail.com> wrote: > >> Hi Chris, > >> > >> Looks good mate. Is there also a way of being able to get the name of > >> the controller or some other variables into the ''it'' strings to make > >> the verbalisations read well for shared specs? > >> > >> like: > >> > >> it "should assign #{@model.to_s.underscore} for the view....." do > > > > How about ... > > > > it "should assign #{@model.humanize} for the view....." do > > Much better and would be fine with me, but the variable replacement > currently doesn''t resolve @model,etc at all unfortunately.Oh, I see what you mean. Unfortunately, there''s not really a good way to do this so the variable is available for both the example name and the example, so for now you''d have to duplicate: describe SomeController do @model = MyModel #this is available for names it_should_behave_like "A CRUD Controller" before(:each) { @model = MyModel } #this is available within examples end What if we were to let it_should_behave_like take some initialization variables as well? it_should_behave_like "A CRUD Controller for", MyModel ???> > Any thoughts where to look? Digging deeper.. > > Cheers, > > Marcus > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
An argument indeed would be effective. As long as things like instance variables are obeying particular conventions, we can make assumptions based on this model class that is passed. For example: describe "list", :shared => true do it "should populate #{model.to_s.underscore.pluralize} by calling #{model}.find(:all)" ... -Chris On 5/5/07, David Chelimsky <dchelimsky at gmail.com> wrote:> On 5/5/07, Marcus Crafter <crafterm at gmail.com> wrote: > > Hi David, > > > > On 05/05/2007, at 12:59 PM, David Chelimsky wrote: > > > > > On 5/4/07, Marcus Crafter <crafterm at gmail.com> wrote: > > >> Hi Chris, > > >> > > >> Looks good mate. Is there also a way of being able to get the name of > > >> the controller or some other variables into the ''it'' strings to make > > >> the verbalisations read well for shared specs? > > >> > > >> like: > > >> > > >> it "should assign #{@model.to_s.underscore} for the view....." do > > > > > > How about ... > > > > > > it "should assign #{@model.humanize} for the view....." do > > > > Much better and would be fine with me, but the variable replacement > > currently doesn''t resolve @model,etc at all unfortunately. > > Oh, I see what you mean. Unfortunately, there''s not really a good way > to do this so the variable is available for both the example name and > the example, so for now you''d have to duplicate: > > describe SomeController do > @model = MyModel #this is available for names > it_should_behave_like "A CRUD Controller" > > before(:each) { @model = MyModel } #this is available within examples > end > > What if we were to let it_should_behave_like take some initialization > variables as well? > > it_should_behave_like "A CRUD Controller for", MyModel > > ??? > > > > > > Any thoughts where to look? Digging deeper.. > > > > Cheers, > > > > Marcus > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >