Grails: Speeding up dependency resolution
Something you might want to consider doing in your project is to lock down specific version of your dependencies instead of getting the latest release. The dependencies closure in our BuildConfig.groovy used to look like this:
dependencies { test "org.codehaus.geb:geb-core:latest.release" test "org.codehaus.geb:geb-spock:latest.release" test "org.seleniumhq.selenium:selenium-chrome-driver:latest.release" test "org.seleniumhq.selenium:selenium-firefox-driver:latest.release" test "org.seleniumhq.selenium:selenium-ie-driver:latest.release" test "org.spockframework:spock-core:0.5-groovy-1.7" }
Every script we ran took about 30-45 secs to resolve dependencies before it did anything, which was quite ridiculous. So after some digging around, Ben and I found out that if we specified the version of the plugins we wanted, that would drastically reduce the time spent resolving those dependencies.
This configuration shaved off about 20-35 seconds from our build:
dependencies { test "org.codehaus.geb:geb-core:0.6.0" test "org.codehaus.geb:geb-spock:0.6.0" test "org.seleniumhq.selenium:selenium-chrome-driver:2.4.0" test "org.seleniumhq.selenium:selenium-firefox-driver:2.4.0" test "org.seleniumhq.selenium:selenium-ie-driver:2.4.0" test "org.spockframework:spock-core:0.5-groovy-1.7" }
Grails: Mocking domain classes in controller specs
I've been working in the Grails space for the last few months and after having done some work in Rails before, I've found Grails to be severely frustrating. One of the problems we faced when writing specs for our controllers is that the available testing frameworks (e.g. Spock) doesn't really have the capability to mock out all domain methods (instance and static) properly when they are called from within an event (e.g. beforeUpdate, beforeDelete).
One way that Ben and I tried was to use Groovy's metaClass to essentially mock out those methods that were called within the domain class events. For example, given the Contact domain class:
public class Contact { def beforeUpdate = { someLocalMethod() } }
And the ContactControllerSpec:
public class ContactControllerSpec extends ControllerSpec { def "should update contact"() { given: def contacts = [new Contact(name: "John Smith", phone: "123456789")] mockDomain(Contact, contacts) when: controller.update() then: ... } }
This test will throw an exception saying that it doesn't recognize the call to
someLocalMethod
So we had to mock it out:
registerMetaClass(Contact) Contact.metaClass.someLocalMethod = {}
The call to
registerMetaClass
ensures that any modifications you've made to the class gets cleaned up at the end of every test.
If someone else knows of a better way to do this, I'd would much appreciate some tips.
Mac OS X: Un-minimizing windows
Some things in the Mac-land aren't as straightforward as I would like, so I thought this was really helpful. To un-minimize windows:
- Press and hold the Apple key.
- While still holding down the Apple key, press and release the Tab key until the application you want is selected.
- While still holding down the Apple key, press and hold the Option key.
- While still holding down the Option key, release the Apple key.
- Release the Option key.
It sounds more complicated than it is, so just try it out. Thanks to adsfushi72 who posted this solution here.