-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow list to accept filter and match on class name #39
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.4.0 | ||
2.5.3 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,19 @@ def execute(output: $stdout) | |
result = Reflectors::List.call(options) | ||
render(result, output) | ||
end | ||
|
||
private | ||
|
||
def render(result, output) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice specialisation here. Eventually, I think we might define the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That’s true, good call. I’ll keep that in mind moving forward! |
||
return not_found(output) if result.empty? | ||
|
||
super(result, output) | ||
end | ||
|
||
def not_found(output) | ||
output.puts "\nSorry, that class doesn't exist 😢", "\n", | ||
'Try something like `Faker::Beer` or `Beer`.', "\n" | ||
end | ||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,23 +7,43 @@ | |
let(:options) { {} } | ||
let(:command) { Faker::Bot::Commands::List.new(options) } | ||
|
||
before do | ||
command.execute(output: output) | ||
end | ||
|
||
context 'when single `list` command' do | ||
it 'executes successfully' do | ||
command.execute(output: output) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see you're warming up to the "mystery guest mitigation" style 😁 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am! Maybe we should talk about standardizing on a spec style across the repo. If you want to standardize on the mystery guest mitigation style, we can remove the ‘let’s and have code that’s duplicated, but easier to reason about. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm definitely open to that. I wonder if we can configure rubocop-rspec to enforce those rules. 🤔 But I really don't have any strong feelings on this one. 🙁 |
||
expect(output.string).to match(/Faker/) | ||
expect(output.string.lines.size).to be_positive | ||
end | ||
|
||
context 'when passing a filter option' do | ||
let(:options) { super().merge(filter: filter) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoah, I didn't know you could call |
||
|
||
context 'when the filter matches' do | ||
let(:filter) { 'Cannabis' } | ||
|
||
it 'executes successfully' do | ||
command.execute(output: output) | ||
expect(output.string).to match(/Faker/) | ||
expect(output.string.lines.size).to be_positive | ||
end | ||
end | ||
|
||
context 'when the filter does not match' do | ||
let(:filter) { 'foobar' } | ||
|
||
it 'returns a not found message' do | ||
command.execute(output: output) | ||
expect(output.string).to match(/Sorry, that class doesn't exist/) | ||
end | ||
end | ||
end | ||
end | ||
|
||
context 'when `list -v` verbose command' do | ||
let(:options) { { verbose: true } } | ||
|
||
it 'executes successfully' do | ||
command.execute(output: output) | ||
constant = output.string.lines[0] | ||
|
||
expect(constant).to match(/Faker::/) | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,44 @@ | |
expect(sample_result_value).to be_a(Array) | ||
expect(sample_result_value).not_to be_empty | ||
end | ||
|
||
context 'when passing a filter' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⭐️ |
||
context 'when filtering by full class name' do | ||
it 'returns filtered descendants and their methods' do | ||
options = { show_methods: true, filter: 'Faker::Beer' } | ||
|
||
reflector = described_class.new(options) | ||
result = reflector.call | ||
|
||
sample_result = result.first | ||
sample_result_key = sample_result.first.to_s | ||
sample_result_value = sample_result.last | ||
|
||
expect(result).to be_a(Hash) | ||
expect(sample_result_key).to eq('Faker::Beer') | ||
expect(sample_result_value).to be_a(Array) | ||
expect(sample_result_value).not_to be_empty | ||
end | ||
end | ||
|
||
context 'when filtering by partial class name' do | ||
it 'returns filtered descendants and their methods' do | ||
options = { show_methods: true, filter: 'Beer' } | ||
|
||
reflector = described_class.new(options) | ||
result = reflector.call | ||
|
||
sample_result = result.first | ||
sample_result_key = sample_result.first.to_s | ||
sample_result_value = sample_result.last | ||
|
||
expect(result).to be_a(Hash) | ||
expect(sample_result_key).to eq('Faker::Beer') | ||
expect(sample_result_value).to be_a(Array) | ||
expect(sample_result_value).not_to be_empty | ||
end | ||
end | ||
end | ||
end | ||
|
||
context 'when show methods is disabled' do | ||
|
@@ -28,13 +66,42 @@ | |
|
||
reflector = described_class.new(options) | ||
result = reflector.call | ||
|
||
sample_result = result.first.to_s | ||
|
||
expect(result).to be_a(Array) | ||
expect(result).not_to be_empty | ||
expect(sample_result).to match(/Faker::/) | ||
end | ||
|
||
context 'when passing a filter' do | ||
context 'when filtering by full class name' do | ||
it 'returns filtered descendants and their methods' do | ||
options = { show_methods: false, filter: 'Faker::Beer' } | ||
|
||
reflector = described_class.new(options) | ||
result = reflector.call | ||
sample_result = result.first.to_s | ||
|
||
expect(result).to be_a(Array) | ||
expect(result).not_to be_empty | ||
expect(sample_result).to eq('Faker::Beer') | ||
end | ||
end | ||
|
||
context 'when filtering by partial class name' do | ||
it 'returns filtered descendants and their methods' do | ||
options = { show_methods: false, filter: 'Beer' } | ||
|
||
reflector = described_class.new(options) | ||
result = reflector.call | ||
sample_result = result.first.to_s | ||
|
||
expect(result).to be_a(Array) | ||
expect(result).not_to be_empty | ||
expect(sample_result).to eq('Faker::Beer') | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for bumping ruby! 👍