Skip to content

Instantly share code, notes, and snippets.

@pqnelson
Created December 18, 2018 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pqnelson/e4133b1cb0966cbb41ce6a5e2d54d278 to your computer and use it in GitHub Desktop.
Save pqnelson/e4133b1cb0966cbb41ce6a5e2d54d278 to your computer and use it in GitHub Desktop.
Random Ruby Notes

Unit testing is best done with BDD in mind.

BDD considers "stories" described in Gherkin (a DSL). Stories have the template:

  • As a (user)
  • In order to (achieve some end)
  • I want to (something to realize that end)

Then we create scenarios which would happen in this story.

BDD scenarios consist of three components:

  • Given [context]
  • When [event]
  • Then [outcome] (Reference 4)

We can add more using And.

The purpose of describe is to wrap a set of tests against one functionality while context is to wrap a set of tests against one functionality under the same state.

Convention

Be clear about what method you are describing. For instance, use the Ruby documentation convention of . (or ::) when referring to a class method's name and # when referring to an instance method's name.

# bad
describe "Launch the rocket!" do
  ...
end

# good
describe Rocket do
  describe "#launch" do
    # tests for the instance method
    ...
  end
end

Recall, a class method in Ruby is analogous to a static method in Java, an instance method in Ruby is analogous to a non-static method in Java.

@pqnelson
Copy link
Author

@pqnelson
Copy link
Author

@pqnelson
Copy link
Author

Something like

<xsl:choose>
  <xsl:when test="$type=1">
    <xsl:apply-templates select="//*[@class='special']"/>
  </xsl:when>
  <xsl:when test="$type=2">
    <xsl:apply-templates select="/foo/bar"/>
  </xsl:when>
  <xsl:otherwise>
    <xsl:apply-templates/>
  </xsl:otherwise>
</xsl:choose>

Could be done in YAML like

choose:
  when:
  - test: "$type=1"
    apply_templates:
      select: "//*[@class=special]"
  - test: "$type=2"
    apply_templates:
      select: "/foo/bar"
  otherwise:
    apply_templates: 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment