Ruby Forum RSpec > Sharing: dont_repeat_yourself plugin custom RSpec matcher

Posted by 21croissants (Guest)
on 29.04.2008 19:28
(Received via mailing list)
I wrote a Rails plugin which uses simian to look for duplicates lines in 
your
code and reports in html format, Textmate or Netbeans.

I wrote it using RSpec and I have included a RSpec custom matcher:
it { rails_application.
with_threshold_of_duplicate_lines(4).
  should be_DRY }

If you use Autotest, your specs will fail the next time you do a nasty
copy-paste !!!

More details in http://21croissants.blogspot.com/2008/03/dry.html

Feedback and patches (with specs!) welcome ;-)

Jean-Michel
--
View this message in context: 
http://www.nabble.com/Sharing%3A-dont_repeat_yourself-plugin-custom-RSpec-matcher-tp16965619p16965619.html
Sent from the rspec-users mailing list archive at Nabble.com.
Posted by Ashley Moran (Guest)
on 29.04.2008 21:39
(Received via mailing list)
On 29 Apr 2008, at 18:25, 21croissants wrote:

> copy-paste !!!
>
> More details in http://21croissants.blogspot.com/2008/03/dry.html
>
> Feedback and patches (with specs!) welcome ;-)

Sounds good!  Any reason why you wrote it as a Rails plugin though?
This could be used for any ruby project... except mine of course, I
never copy and paste, honest :o)

Ashley

--
http://www.patchspace.co.uk/
http://aviewfromafar.net/
Posted by 21croissants (Guest)
on 01.05.2008 17:01
(Received via mailing list)
thanks for your feedback Ashley.

You're right and one of my next action will be to create a gem so it can 
be
use in any ruby project, I will keep the Rails plugin of course.

At the moment, you can write :

require ... specific your location ... +
'/lib/dont_repeat_yourself/reporter'

dry_reporter = DontRepeatYourself::Reporter.new
dry_reporter.configure_simian_for_ruby_project("/home/jeanmichel/ruby/projects/dry-report/rails_plugin/vendor/plugins/dont_repeat_yourself")
dry_reporter.html_rails_report

It will generate the report (HTML, Textmate) in a file called
DRY_report.html at the root folder of your rails app.

I reckon this is not very handy - you need to create a Rails project and
install the plugin - but it will soon improve!

JM


Ashley Moran-4 wrote:
> 
> 
> Sounds good!  Any reason why you wrote it as a Rails plugin though?   
> This could be used for any ruby project... except mine of course, I  
> never copy and paste, honest :o)
> 
> Ashley
> 

--
View this message in context: 
http://www.nabble.com/Sharing%3A-dont_repeat_yourself-plugin%2C-will-report-duplicate-lines-in-your-code%21-tp16965619p16993286.html
Sent from the rspec-users mailing list archive at Nabble.com.
Posted by Ashley Moran (Guest)
on 01.05.2008 18:11
(Received via mailing list)
On 1 May 2008, at 16:00, 21croissants wrote:

> You're right and one of my next action will be to create a gem so it  
> can be
> use in any ruby project, I will keep the Rails plugin of course.

Cool, be sure to post here when you've gemified it :)


>
> It will generate the report (HTML, Textmate) in a file called
> DRY_report.html at the root folder of your rails app.
>
> I reckon this is not very handy - you need to create a Rails project  
> and
> install the plugin - but it will soon improve!


As a spoilt Rails developer I demand that everything written in Ruby
works magically whatever I am doing :o)

This reminds me a bit of a time when I created a Rails project just to
use AR migrations.  I think I'll wait for now until there is a gem
version.

Just out of curiosity, have you run your DRY reporter against the
Rails code itself?  Might be interesting to see the results...

Ashley


--
http://www.patchspace.co.uk/
http://aviewfromafar.net/
Posted by 21croissants (Guest)
on 19.05.2008 19:21
(Received via mailing list)
Ashley, I ran the DRY reporter on Rails 2.0.2 and you'll find the 
results on
http://www.21croissants.com/files/rails_2_0_2_DRY_report.html

I have done a lot of refactoring lately (but did not changed the 
external
API) and will commit my code soon ...


Ashley Moran-4 wrote:
> 
> 
> 
> Just out of curiosity, have you run your DRY reporter against the  
> Rails code itself?  Might be interesting to see the results...
> 
> Ashley
> 
> 

--
View this message in context: 
http://www.nabble.com/Sharing%3A-dont_repeat_yourself-plugin%2C-will-report-duplicate-lines-in-your-code%21-tp16965619p17323753.html
Sent from the rspec-users mailing list archive at Nabble.com.
Posted by Ashley Moran (Guest)
on 19.05.2008 21:53
(Received via mailing list)
On 19 May 2008, at 18:21, 21croissants wrote:

> Ashley, I ran the DRY reporter on Rails 2.0.2 and you'll find the  
> results on
> http://www.21croissants.com/files/rails_2_0_2_DRY_report.html

Wow, that's really interesting.  Some things are trivial mini-methods,
eg "def to_param; to_s; end".  But there are some huge chunks of
complex logic in there!

I wonder how so much duplication got in there, and if some of it is
justified?


> I have done a lot of refactoring lately (but did not changed the  
> external
> API) and will commit my code soon ...

Cool.  Is it still a Rails plugin or can you run it on standalone
code?  It'd make a great gem with a binary.

Be sure to post when you commit!

Ashley


--
http://www.patchspace.co.uk/
http://aviewfromafar.net/