diff --git a/_config.yml b/_config.yml index 59a2c19..9ace8dc 100644 --- a/_config.yml +++ b/_config.yml @@ -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 @@ -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 diff --git a/_includes/nav_footer_custom.html b/_includes/nav_footer_custom.html new file mode 100644 index 0000000..8083c78 --- /dev/null +++ b/_includes/nav_footer_custom.html @@ -0,0 +1 @@ +  \ No newline at end of file diff --git a/_includes/stub_env_vars.html b/_includes/stub_env_vars.html new file mode 100644 index 0000000..017c200 --- /dev/null +++ b/_includes/stub_env_vars.html @@ -0,0 +1,55 @@ +
+

+ + Stub environment variables + +

+ +

Stub environment variables your code requires so your tests become more self-contained, the stub_env gem might help you with that.

+ +
+{% highlight ruby %} +def notify_sales_team + mail( + to: ENV['SALES_TEAM_EMAIL'], + subject: 'New sale' + ) +end +{% endhighlight %} +
+ +
+{% highlight ruby %} +describe '#notify_sales_team' do + it 'prepares the email' do + subject = described_class.notify_sales_team + + expect(subject.to).to eq(['sales-group@company.com']) + expect(subject.subject).to eq('New sale') + end +end +{% endhighlight %} +
+ +
+{% highlight ruby %} +# .env.test +SALES_TEAM_EMAIL='sales-group@company.com' +{% endhighlight %} +
+ +
+{% highlight ruby %} +describe '#notify_sales_team' do + it 'prepares the email' do + stub_env('SALES_TEAM_EMAIL', 'sales-group@company.com') + + subject = described_class.notify_sales_team + + expect(subject.to).to eq(['sales-group@company.com']) + expect(subject.subject).to eq('New sale') + end +end +{% endhighlight %} +
+
diff --git a/index.html b/index.html index eac8d0f..97a29b4 100644 --- a/index.html +++ b/index.html @@ -43,4 +43,5 @@

{% 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 %}