Blog post / Guide to updating Middleman extensions to work with Middleman v4

Hi everyone,

I just published a blog post about updating Middleman extensions to work with Middleman v4: https://www.krautcomputing.com/blog/2017/01/09/updating-middleman-extensions-to-work-with-middleman-v4/
I’d be happy to add more tips, so if anyone has experience in updating an extension, add a comment to the blog post! :slight_smile:

Cheers,
Manuel

@tdreyno What do you think about adding these as an entry to the Middleman docs?

Hiya great article

Not being a ruby developer. I find it quite alien to understand the testing process and what commands to run. Especially when you want to test things against the build structure of middleman.

For instance your ping extension works on the sitemap which is constructed post build, so how do you test this simply against a project that has hundreds of blog posts.

Would be great to understand how to setup and run these tests, and maybe envisage a best practice for middleman components in this journey.

I would be happy to help curate these also.

Hi @iwarner,

Thanks, glad you found the post helpful!

To test an extension, you can use any testing framwork (RSpec and Minitest being the most popular ones) to write unit tests or Cucumber or something similar to write acceptance tests. When using the latter, you can include a “dummy app” with your extension’s tests, which uses the extension (inception!), so you know exactly what should happen when you run the preview server of the dummy app or build the dummy app for example, and can write tests to verify it. It’s much easier to understand if you check out the Cucumber step definitions that Middleman includes.

Funnily enough I tried to get it working for the Sitemap ping extension for hours, and it wouldn’t pick up the request to the Sitemap services, so in the end I gave up and not added any tests for that extension. :smile:

Cheers,
Manuel

Yeah there lies my problem - if a ruby coder like yourself had trouble setting up the inception testing then what is my chances.

I have it working for the basics just not for when I want to test the built files are correct.

In terms of documentation for middleman I think this would be a great start to expand on the framework of testing extensions, and really outline the best practice for this.

I am creating an SEO check extension - that simply parses each document and checks titles, descriptions, open graph etc against expectations.

cheers

Yeah I agree, documenting best practices around extension testing would make sense! I wrote it down as a topic for a future blog post. :smile:

For now I can just recommend to have a look at the Cucumber step definitions I linked to and grep the Middleman source code itself to see how they are used. I also looked at almost all extensions in the extension directory to see how they are tested and find out about best practices.

Cheers,
Manuel