Skip to content

Commit

Permalink
add article
Browse files Browse the repository at this point in the history
  • Loading branch information
glaucocustodio committed Aug 8, 2024
1 parent 032312b commit b9cffba
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
5 changes: 4 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ nav_external_links:
# - title: Guiding principles
# url: "#guiding-principles"
# hide_icon: true
- title: Describe what you are testing
- title: Describe what you're testing
url: "#describe"
hide_icon: true
- title: Use contexts
Expand Down Expand Up @@ -66,6 +66,9 @@ nav_external_links:
- title: Stub HTTP requests
url: "#stub-http-requests"
hide_icon: true
- title: Stub environment variables
url: "#stub-environment-variables"
hide_icon: true
- title: Create only the data you need
url: "#create-only-the-data-you-need"
hide_icon: true
1 change: 1 addition & 0 deletions _includes/nav_footer_custom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
 
55 changes: 55 additions & 0 deletions _includes/stub_env_vars.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<article>
<h2 id="stub-environment-variables">
<a href="#stub-environment-variables">
Stub environment variables
</a>
</h2>

<p>Stub environment variables your code requires so your tests become more self-contained, the <a href="https://rubygems.org/gems/stub_env" target="_blank">stub_env</a> gem might help you with that.</p>

<div class="example">
{% highlight ruby %}
def notify_sales_team
mail(
to: ENV['SALES_TEAM_EMAIL'],
subject: 'New sale'
)
end
{% endhighlight %}
</div>

<div class="bad">
{% highlight ruby %}
describe '#notify_sales_team' do
it 'prepares the email' do
subject = described_class.notify_sales_team

expect(subject.to).to eq(['[email protected]'])
expect(subject.subject).to eq('New sale')
end
end
{% endhighlight %}
</div>

<div class="bad">
{% highlight ruby %}
# .env.test
SALES_TEAM_EMAIL='[email protected]'
{% endhighlight %}
</div>

<div class="good">
{% highlight ruby %}
describe '#notify_sales_team' do
it 'prepares the email' do
stub_env('SALES_TEAM_EMAIL', '[email protected]')

subject = described_class.notify_sales_team

expect(subject.to).to eq(['[email protected]'])
expect(subject.subject).to eq('New sale')
end
end
{% endhighlight %}
</div>
</article>
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ <h2>
{% include dont_use_shared_examples.html %}
{% include mock_external_dependencies.html %}
{% include stub_http_requests.html %}
{% include stub_env_vars.html %}
{% include create_only_the_data_you_need.html %}

0 comments on commit b9cffba

Please sign in to comment.