Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Where to puts test cases (input and output) for Util functions in Rails?

I have a method called valid_ios_deeplink_url? and I want to create some tests for it. Currently, I store the input and the correct output in a hash. Is there any better way to do this?

context 'valid_ios_deeplink_url?' do

    # Accepted iOS Deeplink URL
    test_cases = {
      'myapp://'                     => true,
      'my-app://'                    => true,
      'my.app://'                    => true,
      'myapp://invite'               => true,
      'myapp://?a=42'                => true,
      'myapp://?a=42&b=42'           => true,
      'myapp://invite-friend'        => true,
      'myapp://invite_friend'        => true,
      'myapp://invite?a=42'          => true,
      'myapp://invite?a_1=42'        => true,
      'myapp://invite/friend?a=42'   => true,
      'myapp://invite/friend?a_1=42' => true,
      "myapp"                        => false,
      "myapp:"                       => false,
      "myapp:/"                      => false,
      "myapp://a=42"                 => false,
      "my_app://"                    => false,
      "2myapp://"                    => false,
      ".myapp://"                    => false,
      "+myapp://"                    => false,
      "-myapp://"                    => false,    
    }

    test_cases.each do |url, result|
      it "'#{url}'" do
        is_valid = UrlUtil::valid_ios_deeplink_url?(url)
        expect(is_valid).to be result
      end
    end

  end