[Radiant] Proper Extension Testing

Sean Cribbs seancribbs at gmail.com
Tue Apr 29 10:10:34 CDT 2008


Chris,

For your first question:

it 'should insert an admin tab' do
  Radiant::AdminUI.instance.tabs.any? {|tab| tab.name == "My Tab" 
}.should be_true
end

Not sure what you mean to be testing in your second question.

In your third, I would avoid using the validations test_helper.  Instead 
do something like this:

it 'should validate the format of name' do
  @record.name = 'abc'
  @record.should be_valid
  @record.name = 'cannot contain spaces or tabs'
  @record.should_not be_valid
  @record.should have(1).errors_on(:name)
end

Sean

Chris Parrish wrote:
> So I am writing my first rSpec 'tests' formally and I'm running up 
> against some questions on making this work within Radiant.  Can anyone 
> shed some light on how to spec for the following items:
>
>    * My extension should create a tab in the Admin UI.  It should be
>      before or after certain other tabs.
>
>    * My extension allows the user to customize Radiant::Config items.
>      If the user doesn't explicitly set these, default values should be
>      used.
>
>    * I have a model with a: validates_format_of :name, etc, etc... 
>      declaration.  It should enforce this rule.
>      Note: I've tried testing this last one by copying how Snippets are
>      tested -- i.e:
>          it 'should validate format of name' do
>            assert_valid :name, 'abc', 'abcd-efg', 'abcd_efg',
>      'abc.html', '/', '123'
>            assert_invalid :name, 'cannot contain spaces or tabs'
>          end
>      but this does NOT seem to actually test anything.  I wrote my spec
>      first and it passed without adding the 'validates_format_of' entry
>      in the model.
>
>      This might be showing a bug in the test_helper :validations code. 
>      I commented out the Snippet model's validates_format_of line and
>      it too passed when I ran 'rake spec:models'
>
>
> -Chris
> _______________________________________________
> Radiant mailing list
> Post:   Radiant at radiantcms.org
> Search: http://radiantcms.org/mailing-list/search/
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant
>



More information about the Radiant mailing list