behavior type for steak specs

14 views
Skip to first unread message

Daniel Lopes

unread,
Jul 14, 2010, 12:34:31 PM7/14/10
to Steak
Hello,

I'm working in a project that have near to 500 specs for controllers
specs and I'm starting to add steak specs. In some situation I would
like to have to know the difference between what is a spec from Steak
and what is a Controller.

Rspec already have the concept of behavior_type where we can setup
some things based on the type of spec. For example stub one thing in
controllers and not in model.

In my project I do a lot of setups in acceptance tests but I don't
need this in my other specs but when I run spec spec the
acceptance_helper will be loaded. Don't you guys think that could be
good if Steak specs run as integration tests?

in that way I could do something like:

config.before(:each, :type => :integration) do
@current_account = Factory :account, :domain => "acceptance"
@current_account.owner.activate!

Capybara.default_host = @current_account.full_domain

if options[:js]
Capybara.app_host = "http://#{@current_account.full_domain}:
9887"
Capybara.current_driver = :selenium
end
end

config.after(:each, :type => :integration) do
Capybara.use_default_driver if options[:js]
Capybara.reset_sessions!
end

What do you think?

Thanks in advance.

Luismi Cavallé

unread,
Jul 14, 2010, 4:01:30 PM7/14/10
to ste...@googlegroups.com
Hi, Daniel:

Actually in steak 0.3.x (for Rails 2.x) acceptance specs are registered with the type "acceptance" so something like this should work:

config.before(:each, :type => :acceptance)

This was removed from the rails3 branch (steak 0.4.x) but I think it'd be a good idea to bring it back.

I'll do it as soon as I have some time but you know patches are always welcomed ;)

BTW, There's a related open issue:
http://github.com/cavalle/steak/issues/#issue/12

-- Luismi

Daniel Lopes

unread,
Jul 17, 2010, 12:35:00 AM7/17/10
to ste...@googlegroups.com
Hey Luismi,

I think we should something like that:


But I'm not sure how to test it in the spec folder. The acceptance_helper is coupled with steak way to test things and I don't know if check the type of group is the kind of thing that should lives in acceptance folder.

What do you think?

Thanks,
Daniel Lopes

Wincent Colaiuta

unread,
Jul 17, 2010, 5:30:15 AM7/17/10
to Steak
On 17 jul, 06:35, Daniel Lopes <danielvlo...@gmail.com> wrote:
> Hey Luismi,
>
> I think we should something like that:
>
> http://pastie.org/1048258
>
> But I'm not sure how to test it in the spec folder. The acceptance_helper is
> coupled with steak way to test things and I don't know if check the type of
> group is the kind of thing that should lives in acceptance folder.
>
> What do you think?

Well look how RSpec does it (example, the "helper" type):

http://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/example/helper_example_group.rb#L59

And how it tests it:

http://github.com/rspec/rspec-rails/blob/master/spec/rspec/rails/example/helper_example_group_spec.rb#L21

So, not sure if the same kind of assertion can be made.

Cheers,
Wincent

Luismi Cavallé

unread,
Jul 17, 2010, 6:29:30 AM7/17/10
to ste...@googlegroups.com
On Jul 17, 2010, at 11:30 AM, Wincent Colaiuta wrote:
> On 17 jul, 06:35, Daniel Lopes <danielvlo...@gmail.com> wrote:
>> I think we should something like that:
>>
>> http://pastie.org/1048258

Yep, that's what I meant. There used to be some code like that in steak when we created the rails3 branch.

The only thing with your snippet is that it relies on the presence of rspec-rails and while steak has always been very rails centric I try to avoid the assumption that you are testing a rails application when possible. That code can be easily rewritten without that assumption.

>> But I'm not sure how to test it in the spec folder.

> And how it tests it:
>
> http://github.com/rspec/rspec-rails/blob/master/spec/rspec/rails/example/helper_example_group_spec.rb#L21

Right. Checking for the `type` is what I had in mind to test this functionality. But, in steak, instead of doing it with a unit spec (like in the example from rspec-rails), we shall do it with an acceptance test.

I have some time this weekend so I'm gonna take care of this one.

Cheers!

-- Luismi

Daniel Lopes

unread,
Jul 17, 2010, 8:47:38 AM7/17/10
to ste...@googlegroups.com
Yes, it's the thing that thinking to do but today steak only test his own code with acceptance tests. Should I include a unit folder?

To do the same assertions of rspec we need to require some internals of his test suite.

Sent from my iPhone

Daniel Lopes

unread,
Jul 17, 2010, 8:50:38 AM7/17/10
to ste...@googlegroups.com
Only now I read your message. Great Luismi, thanks.

Sent from my iPhone

Luismi Cavallé

unread,
Jul 17, 2010, 12:19:55 PM7/17/10
to ste...@googlegroups.com
Ok, I've just pushed this commit:

http://github.com/cavalle/steak/commit/5d3a1e976caaf3ad58ff90942febb57f4cdc5f08

Now Steak sets the metadata attribute `type` to `:acceptance` so that we can include modules or set hooks just for our acceptance specs without contaminating the rest of the suite. Like this:

RSpec.configure do |config|
# include MyHelpers module in every acceptance spec
config.include MyHelpers, :type => :acceptance

config.before(:each, :type => :acceptance) do
# Some code to run before any acceptance spec
end
end

Enjoy it!

-- Luismi

Daniel Lopes

unread,
Jul 18, 2010, 9:52:00 PM7/18/10
to ste...@googlegroups.com
Great, thanks a lot Luismi.

Best,
Daniel Lopes
Reply all
Reply to author
Forward
0 new messages