Background just started programming in Ruby literally 12 hours ago and have a question regarding context and describe methods. Reading the RDoc it indicated that "context" is an alias for "describe". So I decided to try to the following syntax seeing this is how I would approach it in C# with NBehave. require ''user'' describe User do before(:each) do @user = User.new end context "(adding assigned role)" do before(:each) do @user.assign_role("Manager") end specify "should be in any roles assigned to it" do @user.should be_in_role("Manager") end specify "should not be in any role not assigned to it" do @user.should_not be_in_role("unassigned role") end end context "(adding assigned group)" do end end I thought I could use the "describe" method to indicate the Type that the specifications where going to be concerning. I then would place the type into a behavioral context to assert the intended behavior against that context. This combination resulted in User never being instantiated for the internal context. (nil:NilClass). However! If I flip the "context" and "description" it works. Am I doing something wrong? require ''user'' context User do ... describe "(adding assigned role)" do ... end end -- God Bless, Joe Ocampo agilejoe.lostechies.com "How do you benefit if you gain the whole world but lose your soul in the process?" Mark 8:36 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080224/1f07d223/attachment.html
On Sun, Feb 24, 2008 at 5:29 AM, Joe Ocampo <agilejoe at gmail.com> wrote:> Background just started programming in Ruby literally 12 hours ago and have > a question regarding context and describe methods. Reading the RDoc it > indicated that "context" is an alias for "describe". So I decided to try to > the following syntax seeing this is how I would approach it in C# with > NBehave. > require ''user'' > > describe User do > > before(:each) do > @user = User.new > end > > context "(adding assigned role)" do > before(:each) do > @user.assign_role("Manager") > end > > specify "should be in any roles assigned to it" do > @user.should be_in_role("Manager") > end > > specify "should not be in any role not assigned to it" do > @user.should_not be_in_role("unassigned role") > end > end > > context "(adding assigned group)" do > > end > end > > I thought I could use the "describe" method to indicate the Type that the > specifications where going to be concerning. I then would place the type > into a behavioral context to assert the intended behavior against that > context.At first glance, that is really cool. We''ve also batted around some other names like #facet or #behaviour.> This combination resulted in User never being instantiated for the internal > context. (nil:NilClass). However! If I flip the "context" and > "description" it works. Am I doing something wrong?No you''re not doing something wrong - there are two different places where describe is defined. One in main (the outermost layer) and one inside an ExampleGroup. The one in the example group isn''t aliased. So to solve that for the short term in your own code you can do this in your spec_helper.rb file: module Spec::Example::ExampleGroupMethods alias :context :describe end In terms of getting that into RSpec, why don''t you enter a feature request at http://rspec.lighthouseapp.com and we can discuss the merits of this there. As I said, I like it at first glance, but I want to think about it and get other opinions before just adding it (as context is only there for backwards compatibility right now). Thanks, David> > require ''user'' > > context User do > ... > describe "(adding assigned role)" do > ... > end > end > > -- > God Bless, > > Joe Ocampo > agilejoe.lostechies.com > > "How do you benefit if you gain the whole world but lose your soul in the > process?" Mark 8:36 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
>At first glance, that is really cool. We''ve also batted around some >other names like #facet or #behavior.LOL..I smile because we went through the same semantic struggles as well. The funny thing is the rSpec project led us to our resolve. :-) We basically came to this conclusion every object has a behavior but that behavior is governed by a context or multiple context concerning that type. Given that we are specifying how an object should behave under a certain context, the DSL quickly took shape. About the only difference is we introduced the term [concerning] instead of describe. pseudo DSL: these specs are concerning this [Type] when this [type] is in this context then specify that it should behave this way In C# this DSL creates a lot of noise in the syntax! For example: [Context, Concerning("EquationGenerator")] public class When_initializing_the_EquationGenerator_with_one_and_five : NBehave.NUnitSpecBase { protected override void Before_each_spec() { _generator = new EquationGenerator(_LowerBound, _UpperBound); } [Specification] public void Should_generate_equations_where_the_left_hand_side_is_greater_than_or_equal_to_the_lower_bound() { IList<Equation> equations = _generator.GenerateEquations(); foreach (Equation equation in equations) { equation.LeftHandSide.should_be_greater_than_or_equal_to (_LowerBound); } } [Specification] public void Should_generate_equations_where_the_left_hand_side_is_less_than_or_equal_to_the_upper_bound()... [Specification] public void Should_generate_equations_where_the_right_hand_side_is_greater_than_or_equal_to_the_lower_bound()... [Specification] public void Should_generate_equations_where_the_right_hand_side_is_less_than_or_equal_to_the_upper_bound()... [Specification] public void Should_generate_twenty_five_equations()... } I think we have taken this as far as it can go for a statically typed language. Hence my interest in rSpec especially once MS gets IronRuby baked! I can easily see Ruby taking over the MS culture once IronRuby is complete. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080224/390f8ba5/attachment.html
On Sun, Feb 24, 2008 at 6:26 AM, David Chelimsky <dchelimsky at gmail.com> wrote:> In terms of getting that into RSpec, why don''t you enter a feature > request at http://rspec.lighthouseapp.com and we can discuss the > merits of this there. As I said, I like it at first glance, but I want > to think about it and get other opinions before just adding it (as > context is only there for backwards compatibility right now).I like it. I always say that you can''t really specify an object''s behavior without considering its context. This seems like it would be a nice organizational tool, and contribute to the over all vision of BDD. Pat