Skip to content

bob: added generator#657

Merged
kotp merged 1 commit intoexercism:masterfrom
ajwann:add-generator-for-bob
Jun 10, 2017
Merged

bob: added generator#657
kotp merged 1 commit intoexercism:masterfrom
ajwann:add-generator-for-bob

Conversation

@ajwann
Copy link
Copy Markdown
Contributor

@ajwann ajwann commented May 25, 2017

references #396


def feedback(text)
"Bob hears #{text.inspect}, and.."
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really belongs in the generator, the feedback should be expanded before it gets added to the test.

"Bob hears #{text.inspect}, and.."
end

<% test_cases.each_with_index do |test_case, idx| %>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use index instead of idx

Copy link
Copy Markdown
Member

@kotp kotp May 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @Insti use either index or use i. I prefer i in block argument lists when it is used as an index, otherwise I prefer fully expressing the idea as a word.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm totally fine with either. Index is more explicit, so I'll go with that.

class <%= exercise_name_camel %>Test < Minitest::Test
def bob
Bob
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point of this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly just tried to reproduce the test pretty much in it's entirety. I agree this method is especially useless. I'm happy to remove it forever.

@Insti
Copy link
Copy Markdown
Contributor

Insti commented May 26, 2017

Looking good @ajwann, you're getting good at these.

@ajwann ajwann force-pushed the add-generator-for-bob branch from 2ed109e to 2448c84 Compare May 30, 2017 22:35
@ajwann
Copy link
Copy Markdown
Contributor Author

ajwann commented May 30, 2017

@Insti I made changes based on you and @kotp's feedback. I also got rid of the call to inspect altogether when interpolating the input in the workload method. Unless I'm missing something it's not necessary anymore.

Comment thread exercises/bob/bob_test.rb Outdated
def test_other_whitespace
skip
remark = "
"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someones newlines are not being managed in their git configuration?

Copy link
Copy Markdown
Contributor

@Insti Insti May 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an explicit \n\r(!) in the test data.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly think that working with the various newlines that we have to deal with is an important thing... but why in this exercise. Not appropriate to press back here though... should be addressed in x-common.

Comment thread exercises/bob/bob_test.rb Outdated
remark = "\t" * rand(1..10)
assert_equal 'Fine. Be that way!', bob.hey(remark), feedback(remark)
remark = " "
assert_equal 'Fine. Be that way!', Bob.hey(remark), "Bob hears , and.."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The things that Bob hears should be quoted.
%Q can be good for this to help avoid needing to quote quotes.

@Insti
Copy link
Copy Markdown
Contributor

Insti commented May 31, 2017

The inspects are essential in this exercise due to all the wacky whitespace characters present in the canonical data.

@ajwann ajwann force-pushed the add-generator-for-bob branch from 2448c84 to 35e151d Compare June 5, 2017 23:31
@ajwann
Copy link
Copy Markdown
Contributor Author

ajwann commented Jun 5, 2017

I think we are good to go here.

Comment thread exercises/bob/bob_test.rb Outdated
remark = "\t" * rand(1..10)
assert_equal 'Fine. Be that way!', bob.hey(remark), feedback(remark)
remark = %Q( )
assert_equal 'Fine. Be that way!', Bob.hey(remark), %Q(Bob hears , and..)
Copy link
Copy Markdown
Contributor

@Insti Insti Jun 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still needs quotes around the string Bob hears. (input)
You didn't put the inspects back?


class BobCase < Generator::ExerciseCase
def workload
indent_lines(["remark = %Q(#{input})",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use inspect here rather than %Q

class BobCase < Generator::ExerciseCase
def workload
indent_lines(["remark = %Q(#{input})",
"assert_equal '#{expected}', Bob.hey(remark), %Q(Bob hears #{input}, and..)"
Copy link
Copy Markdown
Contributor

@Insti Insti Jun 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%Q is right to use here though.
But add an inspect.

"assert_equal '#{expected}', Bob.hey(remark), %Q(Bob hears #{input.inspect}, and..)"

Copy link
Copy Markdown
Contributor Author

@ajwann ajwann Jun 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Insti Adding inspect here actually causes several tests to close the %Q() call early, because those test cases contain literal ) in the actual values. This causes a syntax error on line 101 of the generated test.

If I do something like 'Bob hears #{input.inspect}, and..' then I get the same issue because certain output contains '.

I'm basically trapped in a big catch 22.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

I will look soon if @Insti doesn't beat me to it.

Copy link
Copy Markdown
Member

@kotp kotp Jun 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try doing the same with the %Q but instead use %\Q to escape it. That should reconstruct the invocable line, but ignore it in place.

Let me know.

Copy link
Copy Markdown
Contributor

@Insti Insti Jun 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work?

  def workload
    indent_lines(["remark = #{input.inspect}",
      "assert_equal '#{expected}', Bob.hey(remark), %q{Bob hears #{input.inspect}, and..}"
    ], 4)
  end

Copy link
Copy Markdown
Contributor

@Insti Insti Jun 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lowercase %q is better since we don't want it interpolating the string. (the second time)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Insti using %q with curly brackets insted of parens did the trick. I had no idea you could use alternative delimiters, thanks!

Comment thread exercises/bob/bob_test.rb Outdated
def test_other_whitespace
skip
remark = %Q(
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using inspect should also make the silly whitespace characters usefully visible.

Copy link
Copy Markdown
Contributor

@Insti Insti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ajwann, we're nearly there, just need to put the inspects back.

@ajwann ajwann force-pushed the add-generator-for-bob branch from 35e151d to 7c7db85 Compare June 8, 2017 22:59
@ajwann
Copy link
Copy Markdown
Contributor Author

ajwann commented Jun 8, 2017

The calls to inspect are back and the whitespace characters now show up when the test is generated.

require_relative '<%= exercise_name %>'

# Common test data version: <%= canonical_data_version %> <%= abbreviated_commit_hash %>
class <%= exercise_name_camel %>Test < Minitest::Test
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks just like the default test template, are there any changes or can it be deleted?

Copy link
Copy Markdown
Contributor Author

@ajwann ajwann Jun 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes, it got copied when I copied the generator directory. I'll get rid of it.

@ajwann ajwann force-pushed the add-generator-for-bob branch from 7c7db85 to 81184b1 Compare June 8, 2017 23:30
Copy link
Copy Markdown
Contributor

@Insti Insti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is done. 👍

@kotp kotp merged commit 11b3b41 into exercism:master Jun 10, 2017
@Insti
Copy link
Copy Markdown
Contributor

Insti commented Jun 10, 2017

Thanks for all your work on this @ajwann ❤️ ⭐️

@Insti Insti mentioned this pull request Oct 1, 2017
94 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants